UIAppearence仅在iOS中使用系统颜色?

时间:2014-07-10 14:20:28

标签: ios uinavigationbar uiappearance

我正在尝试使用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

有什么建议吗?

2 个答案:

答案 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.01.0之间的四个值。因此,如果您拥有从0.0255.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]