/* 全局设置 */
// TabBar背景颜色
[UITabBar appearance].barTintColor = [UIColor whiteColor];
/* 单独设置 */
// TabBar背景颜色
self.tabBarController.tabBar.barTintColor = [UIColor whiteColor];
TabBar图标颜色
不用写乱七八糟的代码,直接到 Assets.xcassets 里把图片的属性 Render 设置为 Original Image 就可以让颜色按照图片的来,而不会选中变蓝了。

Button
// 字体颜色
// 有人可能会误用这两个错误的方法
// 错误1:[button.titleLabel setTextColor:[UIColorblackColor]];
// 错误2:button.titleLabel.textColor = [UIColor redColor];
// 正确
[button setTitleColor:[UIColor blackColor]
forState:UIControlStateNormal];
// 边框颜色
// 默认没有边框,第一行是设置线条,第二行重点在于layer的颜色要用CGColor
button.layer.borderWidth = 2.0;
button.layer.borderColor = [UIColor blackColor].CGColor;
TextField
// placeholder颜色设置
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"placeHoldtext" attributes:@{NSForegroundColorAttributeName: [UIColor redColor]}];
AttributedString
// 初始化NSMutableAttributedString
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String"];
// 颜色设置
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor blueColor]
range:NSMakeRange(0,5)];
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:NSMakeRange(6,12)];
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor greenColor]
range:NSMakeRange(19,6)];
// 字体设置
[str addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:30.0]
range:NSMakeRange(0, 5)];
[str addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0]
range:NSMakeRange(6, 12)];
[str addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"Courier-BoldOblique" size:30.0]
range:NSMakeRange(19, 6)];
// 把AttributedString赋值给Label
attrLabel.attributedText = str;
通用部分
// 字体颜色 适用于Label、TextField、TextView等
label.textColor = [UIColor whiteColor];
textField.textColor = [UIColor yellowColor];
textView.textColor = [UIColor yellowColor];
// 背景颜色 基本都使用
someView.backgroundColor = [UIColor whiteColor];
工具
系统自带的测色工具,位置在 应用程序 -> 实用工具( Launchpad 里叫其他) -> 数码测色计










