UITabBar标题十六进制值

时间:2013-12-10 08:41:47

标签: ios uitabbarcontroller uitabbar uitabbaritem

我需要为UITabBar标题设置六进制十进制值(特定颜色值)。我知道下面的代码是正常的。我需要设置十六进制值而不是蓝色。如果我需要设置#33223意味着我该怎么办?

 [[UITabBarItem appearance] setTitleTextAttributes:@{UITextAttributeTextColor :[UIColor colorWithRed:5 green:112 blue:180 alpha:2]} forState:UIControlStateNormal];

2 个答案:

答案 0 :(得分:1)

- (UIColor *)getUIColorObjectFromHexString:(NSString *)hexStr alpha:(CGFloat)alpha
{
  // Convert hex string to an integer
  unsigned int hexint = [self intFromHexString:hexStr];

  // Create color object, specifying alpha as well
  UIColor *color =
    [UIColor colorWithRed:((CGFloat) ((hexint & 0xFF0000) >> 16))/255
    green:((CGFloat) ((hexint & 0xFF00) >> 8))/255
    blue:((CGFloat) (hexint & 0xFF))/255
    alpha:alpha];

  return color;
}

用法:

NSString *hexStr1 = @"123ABC";
UIColor *color1 = [self getUIColorObjectFromHexString:hexStr1 alpha:.9];
NSLog(@"UIColor: %@", color1);

答案 1 :(得分:0)

将十六进制颜色翻译为Rgb并使用[UIColor colorWithRed:200 green:191 blue:231 alpha:1]