/** color转image */ (UIImage)createImageWithColor: (UIColor)color { CGRect rect=CGRectMake(0.0f, 0.0f
#pragma mark - 颜色转换 IOS中十六进制的颜色转换为UIColor + (UIColor *) colorWithHexString: (NSString *)color {...]; // String should be 6 or 8 characters if ([cString length] < 6) { return [UIColor...= 6) return [UIColor clearColor]; // Separate into r, g, b substrings NSRange...gString] scanHexInt:&g]; [[NSScanner scannerWithString:bString] scanHexInt:&b]; return [UIColor
开发对于方法的拓展实在不行,不像 android 可以直接加载十六进制色值 我在国外论坛上,看到大佬的一种写法,感觉很有用,这里分享给大家 二、实现 下面我将逐步提出几种方案,一步步优化,知道最后可以直接使用:UIColor...所以你可以使用 0x 前缀的十六进制表示法,来设置 UIColor,例如 0xFF 为了简化转换,让我们先创建一个已整数(0-255)为参数的构造方法 extension UIColor {...(red: 0xFF, green: 0xFF, blue: 0xFF) let color2 = UIColor(rgb: 0xFFFFFF) 2.2 通过 CGFloat 设置设置透明度 如何设置...UIColor 透明度?...我们一般使用 UIColor.withAlphaComponent 来设置颜色的透明度,例如 let semitransparentBlack = UIColor(rgb: 0x000000).withAlphaComponent
UIColor *newColor = [UIColor colorFromRGBAArray:colorArray]; RGBA字典与颜色的相互转换 预定义的四个键是: kColoursRGBA_R...*newColor1 = [UIColor colorFromHSBAArray:colorArray]; UIColor *newColor2 = [UIColor colorFromHSBADictionary...UIColor *newColor1 = [UIColor colorFromCIE_LabArray:colorArray]; UIColor *newColor2 = [UIColor colorFromCIE_LabDictionary...*newColor1 = [UIColor colorFromCMYKArray:colorArray]; UIColor *newColor2 = [UIColor colorFromCMYKDictionary...= [[UIColor tomatoColor] alpha]; 颜色变亮/变暗 // 取值范围 0->1 UIColor *lighterColor = [[UIColor seafoamColor]
=======下面三个渐变色必须全部设置 否则效果可能与预期不同================// /** *设置圆弧渐变色的起始色 */ @property(nonatomic,strong)UIColor... */ @property(nonatomic,strong)UIColor * maxLineColor; /** *设置圆弧背景色 */ @property(nonatomic,strong)...UIColor * lineTintColor; /** *设置进度 */ @property(nonatomic,assign)CGFloat progress; /** *设置线的宽度 max... yellowColor]; _midLineColor = [UIColor orangeColor]; _maxLineColor = [UIColor redColor]; ..._lineTintColor = [UIColor grayColor]; _progress = 1; _lineWidth = 4; _lineTintColor = [UIColor
let view = UIView(frame:CGRect(x:40, y:80,width:240, height:240)) view.backgroundColor = UIColor.black...CGRect(x:40, y:80,width:240, height:240)) let image = UIImage(named:“Sample”) view.backgroundColor = UIColor.init...设置阴影: view.layer.shadowColor = UIColor.black.cgColor view.layer.shadowOffset = CGSize(width:10.0,height...override init(frame:CGRect) { super.init(frame:frame) self.backgroundColor = UIColor.clear } override...let midColor = UIColor.blue.cgColor let toColor = UIColor.red.cgColor gradientLayer.colors = [fromColor
颜色适配 iOS 13 之前 UIColor 只能表示一种颜色,从 iOS 13 开始 UIColor 是一个动态的颜色,它可以在 LightMode 和 DarkMode 拥有不同的颜色。...// UIColor 增加的颜色 @available(iOS 13.0, *) open class var systemBackground: UIColor { get } @available(...: UIColor { get } ......view.backgroundColor = UIColor.systemBackground label.textColor = UIColor.label placeholderLabel.textColor...并赋值给 view.backgroundColor 和 label,代码如下 let backgroundColor = UIColor { (trainCollection) -> UIColor
我这里就是因为H5中的颜色是 #3983E5,而是使用如下方法转换的UIColor有误差: + (UIColor *) colorWithHexString: (NSString *)color {...= 6) return [UIColor clearColor]; // Separate into r, g, b substrings NSRange range...然后原生自定义了一个把16进制颜色转换成UIColor 的方法。 想要使网页的导航栏颜色与状态栏颜色完全一致,那么只需要换一种方式。 使用RGBA颜色表示法即可。...比如,我这里H5中导航栏颜色改为(1,159,239,1),然后工程里只需要将self.view的背景色用[UIColor colorWithRed:r/255.0 green:g/255.0 blue...#define RGB(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a] 我这里这样设置self.view
UIColor?...() -> UIColor?...) -> UIColor?...func dividerColor() -> UIColor?...{ return UIColor(hex: "#ffe700ff") } // 背景颜色 static func backgrounColor() -> UIColor
(); //设置bar的颜色 appear.barTintColor = UIColor(red: 39/255, green: 157/255, blue: 244/255, alpha: 1.0);...//设置背景色(不透明时没用,因为barTintColor在backgroundColor的上一层) appear.backgroundColor = UIColor(red: 39/255, green...clearColor]; appear.barTintColor = [UIColor colorWithRed:52.0/255 green:146.0/255 blue:233.0/255 alpha...:1]; appear.backgroundColor = [UIColor colorWithRed:52.0/255 green:146.0/255 blue:233.0/255 alpha:1];...: 240/255, blue: 240/255, alpha: 1.0); searchBarAppear.layer.borderColor = UIColor(hexString: "#ffffff
UIView * redV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; redV.backgroundColor = [UIColor...UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; lbl.text = @"我"; lbl.textColor = [UIColor...whiteColor]; lbl.textAlignment = NSTextAlignmentCenter; lbl.backgroundColor = [UIColor blackColor...UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; lbl.text = @"我"; lbl.textColor = [UIColor...whiteColor]; lbl.textAlignment = NSTextAlignmentCenter; lbl.backgroundColor = [UIColor blackColor
@implementation BezierView - (void)drawRect:(CGRect)rect { // Drawing code //设置线条颜色 UIColor...*color = [UIColor redColor]; [color set]; //创建UIBezierPath UIBezierPath *apath = ({...:(CGPoint)controlPoint; 上代码: - (void)drawRect:(CGRect)rect { // Drawing code //设置线条颜色 UIColor...*color = [UIColor redColor]; [color set]; //创建UIBezierPath UIBezierPath *apath = ({...上代码: - (void)drawRect:(CGRect)rect { // Drawing code //设置线条颜色 UIColor *color = [UIColor
)]; [button1 setTitle:@"button1" forState:UIControlStateNormal]; button1.backgroundColor = [UIColor...button1普通状态下的背景色 - (void)button1BackGroundNormal:(UIButton *)sender { sender.backgroundColor = [UIColor...button1高亮状态下的背景色 - (void)button1BackGroundHighlighted:(UIButton *)sender { sender.backgroundColor = [UIColor...setTitle:@"button2" forState:UIControlStateNormal]; [button2 setBackgroundImage:[self imageWithColor:[UIColor...redColor]] forState:UIControlStateNormal]; [button2 setBackgroundImage:[self imageWithColor:[UIColor
于是,我们可以通过为 UIColor 增加 extension 扩展的方式,来为 App 的背景色和字体颜色做适配,代码如下: import UIKit extension UIColor {...) { return UIColor{(trainCollection) -> UIColor in if trainCollection.userInterfaceStyle...{ if #available(iOS 13.0, *) { return UIColor{(trainCollection) -> UIColor in...{ if #available(iOS 13.0, *) { return UIColor{(trainCollection) -> UIColor in...{ if #available(iOS 13.0, *) { return UIColor{(trainCollection) -> UIColor in
150, 80)]; [iconBtn setTitle:@"我的好友" forState:UIControlStateNormal]; [iconBtn setTitleColor:[UIColor...CGColor; //边框颜色 iconBtn.layer.borderWidth = 1; //边框宽度 iconBtn.titleLabel.backgroundColor = [UIColor...greenColor]; //文字颜色 iconBtn.imageView.backgroundColor = [UIColor blackColor]; //图片颜色 [iconBtn...forState:UIControlStateNormal]; btn.titleLabel.numberOfLines = 0; [btn setBackgroundColor:[UIColor...greenColor]; //文字颜色 iconBtn.imageView.backgroundColor = [UIColor blackColor]; //图片颜色 [iconBtn
implementation UINavigationBar (UINavigationBarCategory) - (void)drawRect:(CGRect)rect { //颜色填充 // UIColor...*color = [UIColor redColor]; // CGContextRef context = UIGraphicsGetCurrentContext(); // CGContextSetFillColor...CGColorGetComponents( [color CGColor])); // CGContextFillRect(context, rect); // self.tintColor = color; //图片填充 UIColor...*color = [UIColor colorWithRed:46.0f/255.0f green:87.0f/255.0f blue:29.0f/255.0f alpha:1.0f]; UIImage
.定义代理方法: @objc protocol ChangeColorDelegate: class { /// 必须实现的方法 func changeClolor(_ clolor:UIColor...: class { /// 必须实现的方法 func changeClolor(_ clolor:UIColor) /// 非必须实现方法 } 2.申明代理属性(weak...self 5.在需要调用的地方写代理方法 extension ViewController:ChangeColorDelegate{ func changeClolor(_ clolor: UIColor...import UIKit @objc protocol ChangeColorDelegate: class { /// 必须实现的方法 func changeClolor(_ clolor:UIColor...nil) } } ///代理方法 extension ViewController:ChangeColorDelegate{ func changeClolor(_ clolor: UIColor
/**标题字体*/ @property (strong, nonatomic) UIFont *titleFont; /**标题颜色*/ @property (strong, nonatomic) UIColor...]; self.titleFont = [UIFont systemFontOfSize:13.f]; } else { self.titleColor = [UIColor...*messageColor; /** 副标题颜色 */ @property(nonatomic, strong) UIColor *lineColor; /** 副标题字体,默认16,未加粗 */ @...grayColor]; _textAlignment = NSTextAlignmentCenter; _lineColor = [UIColor lightGrayColor]; }...brownColor]; alert.messageColor = [UIColor blueColor]; action1.titleColor = [UIColor blueColor
button frmae button.frame = CGRectMake(100, 100, 100, 100); //设置button 背景颜色 button.backgroundColor = [UIColor...添加button的标题 [button setTitle:@"登陆" forState:UIControlStateNormal]; //设置标题的颜色 [button setTitleColor:[UIColor...[UIImage imageNamed:@"7.png"] forState:UIControlStateNormal]; //设置阴影颜色 [button setTitleShadowColor:[UIColor...]; 设置button某个状态阴影的标题颜色 - (void)setTitleShadowColor:(nullable UIColor *)color forState:(UIControlState...)state 例:[button setTitleShadowColor:[UIColor purpleColor] forState:UIControlStateNormal]; 设置button某个状态图片
self.view addSubview:view]; UIView *view2 = [[UIView alloc] init]; view2.backgroundColor = [UIColor...UIViewController *controller1 =[[UIViewController alloc]init]; controller1.view.backgroundColor = [UIColor...UIViewController *controller2 =[[UIViewController alloc]init]; controller2.view.backgroundColor = [UIColor...UIViewController *controller3 =[[UIViewController alloc]init]; controller3.view.backgroundColor = [UIColor...UIViewController *controller4 =[[UIViewController alloc]init]; controller4.view.backgroundColor = [UIColor
领取专属 10元无门槛券
手把手带您无忧上云