0

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];
user3073276
  • 74
  • 1
  • 2
  • 13

2 Answers2

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

Usage:

NSString *hexStr1 = @"123ABC";
UIColor *color1 = [self getUIColorObjectFromHexString:hexStr1 alpha:.9];
NSLog(@"UIColor: %@", color1);
Pradhyuman sinh
  • 3,936
  • 1
  • 23
  • 38
0

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

Vaionixx
  • 400
  • 2
  • 11
  • It's not working. See edited code what i did. Same white color only displaying. – user3073276 Dec 10 '13 at 09:23
  • why it's not taking custom RGB value color? – user3073276 Dec 10 '13 at 09:36
  • it should take custom color. sry It should be floats. so 200/255.0f and so one would make it work. So #008000 = gree, UIColor *greenColor = [UIColor colorWithRed:0/255.0 green:128/255.0 blue:0/255.0f alpha:1] This should give you a green color. I only get black color for your hex #33223. – Vaionixx Dec 10 '13 at 10:14