gpt4 book ai didi

ios - UITabBar 标题十六进制值

转载 作者:行者123 更新时间:2023-11-29 03:25:37 24 4
gpt4 key购买 nike

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

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

最佳答案

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

关于ios - UITabBar 标题十六进制值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20489673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com