我正在尝试使用UIAppearance更改应用中导航栏的颜色。
但是只有当我使用系统颜色时,它才有效:
UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
[navigationBarAppearance setBarTintColor:[[UIColor alloc] initWithRed:220.0f green:47.0f blue:40.0f alpha:100.0f]]; // does not work
[navigationBarAppearance setBarTintColor:[UIColor colorWithRed:220.0f green:47.0f blue:40.0f alpha:100.0f]]; // does not work
[navigationBarAppearance setBarTintColor:[UIColor redColor]]; // works
有什么建议吗?
答案 0 :(得分:1)
我认为你在自定义颜色方法上做错了,就像这样
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:127.0f/255.0f green:127.0f/255.0f blue:127.0f/255.0f alpha:1.0f]];
答案 1 :(得分:1)
方法
colorWithRed:green:blue:alpha:
接受0.0
和1.0
之间的四个值。因此,如果您拥有从0.0
到255.0
的组件,则需要使用255.0f
进行归一化。
[UIColor alloc] initWithRed:220.0f/255.0f green:47.0f/255.0f blue:40.0f/255.0f alpha:100.0f/255.0f]