自定义选择图片颜色
[[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithHexString:@"52b800"]];
自定义选择字体颜色
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys: [UIColor colorWithHexString:@"52b800"],
UITextAttributeTextColor, nil] forState:UIControlStateSelected];
+ (UIColor *)colorWithRGBHex:(UInt32)hex {
int r = (hex >> 16) & 0xFF;
int g = (hex >> 8) & 0xFF;
int b = (hex) & 0xFF;
return [UIColor colorWithRed:r / 255.0f
green:g / 255.0f
blue:b / 255.0f
alpha:1.0f];
}
// Returns a UIColor by scanning the string for a hex number and passing that to +[UIColor colorWithRGBHex:]
// Skips any leading whitespace and ignores any trailing characters
+ (UIColor *)colorWithHexString:(NSString *)stringToConvert {
NSScanner *scanner = [NSScanner scannerWithString:stringToConvert];
unsigned hexNum;
if (![scanner scanHexInt:&hexNum]) return nil;
return [UIColor colorWithRGBHex:hexNum];
}