2013-12-10 61 views
0

我需要爲UITabBar標題設置十六進制值(特定顏色值)。我知道下面的正常代碼。我需要設置十六進制值而不是藍色。如果我需要設置#33223意味着我能做什麼?UITabBar title hexa value

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

這可以幫助你與http://stackoverflow.com/questions/6207329/how -to-set-hex-color-code-for-background –

+0

我在問如何爲UITabBar標題使用十六進制的十六進制值? – user3073276

回答

0

翻譯的六色RGB和使用[UIColor colorWithRed:200 green:191 blue:231 alpha:1]

+0

這不起作用。看到我編輯過的代碼。僅顯示相同的白色。 – user3073276

+0

爲什麼不採用自定義的RGB值顏色? – user3073276

+0

它應該採取自定義顏色。 sry它應該是浮動的。所以200/255.0f,所以人們會使它工作。所以#008000 = gree,UIColor * greenColor = [UIColor colorWithRed:0/255.0 green:128/255.0 blue:0/255.0f alpha:1]這會給你一個綠色。我只得到黑色的十六進制#33223。 – Vaionixx

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