Question

I need to set hexa decimal value (particular color value) for UITabBar title. I know the below the code for normal. I need to set hexadecimal value instead of blue color. If i need to set #33223 means what can i do?

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

Solution 2

Translate the hexa color to Rgb and use [UIColor colorWithRed:200 green:191 blue:231 alpha:1]

OTHER TIPS

- (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;
}

Usage:

NSString *hexStr1 = @"123ABC";
UIColor *color1 = [self getUIColorObjectFromHexString:hexStr1 alpha:.9];
NSLog(@"UIColor: %@", color1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top