Translate the hexa color to Rgb and use [UIColor colorWithRed:200 green:191 blue:231 alpha:1]
UITabBar title hexa value
-
30-08-2022 - |
Domanda
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];
Soluzione 2
Altri suggerimenti
- (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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow