UIAppearence是否仅在iOS中使用系统颜色?
我正在尝试使用UIAppearance更改我应用程序中导航栏的颜色 但只有当我使用系统颜色时,它才起作用:UIAppearence是否仅在iOS中使用系统颜色?,ios,uinavigationbar,uiappearance,Ios,Uinavigationbar,Uiappearance,我正在尝试使用UIAppearance更改我应用程序中导航栏的颜色 但只有当我使用系统颜色时,它才起作用: UINavigationBar *navigationBarAppearance = [UINavigationBar appearance]; [navigationBarAppearance setBarTintColor:[[UIColor alloc] initWithRed:220.0f green:47.0f blue:40.0f alpha:100.0f]]
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
有什么建议吗?我认为你用自定义颜色的方法做得不对,就是这样
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:127.0f/255.0f green:127.0f/255.0f blue:127.0f/255.0f alpha:1.0f]];
方法
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]
您应该已经阅读了
UIColor
的文档。您使用的方法接受介于0.0和1.0之间的值,而不是介于0.0和255.0之间的值。@duci9y您是对的。不幸的是,你确实是以评论而不是回复的形式发布的,所以我不得不接受Fry的回复,尽管他发布的时间比你晚。