Why can't I set a custom color-tint for the UINavigationBar?

删除回忆录丶 提交于 2019-12-23 18:33:54

问题


I want to change the color on the navigation bar and the documentation states not to attempt to change the 'alpha' value. So, how can I set a color that is not the SDK defined values (e.g., [UIColor redColor], brownColor, etc.) if all the constructors provide an alpha value? I tried getting the current alpha value but that did not help. When I use a custom color, it causes the navigation bar to look like an x-ray (a scraggy, black-on-white).

[self.navigationController.navigationBar setTintColor: [UIColor brownColor]];

回答1:


I can be such an idiot ... for months now, I assumed the values ranged from 0..255 (i.e., HTML color values), but they are in the range [0.0 .. 1.0]. Now that I set my 0..255 value and normalize it to 0..1 it works as expected. I wrote a simple color-slider application and when I was debugging it, is when I realized my mistake.




回答2:


Try this:

When creating the UINavigationController initially

MyNavigationController *navigationController = [[MyNavigationController alloc] init];
[[navigationController navigationBar] setTintColor:[UIColor redColor]];


来源:https://stackoverflow.com/questions/2706584/why-cant-i-set-a-custom-color-tint-for-the-uinavigationbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!