为什么我不能为UINavigationBar设置自定义色调? [英] Why can't I set a custom color-tint for the UINavigationBar?

查看:106
本文介绍了为什么我不能为UINavigationBar设置自定义色调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改导航栏上的颜色,并且文档指出不要尝试更改'alpha'值.那么,如果所有构造函数都提供一个alpha值,我该如何设置不是SDK定义值的颜色(例如[UIColor redColor],brownColor等)?我尝试获取当前的alpha值,但这没有帮助.当我使用自定义颜色时,它会使导航栏看起来像X射线(粗cra的黑底白字).

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]];

推荐答案

我可以成为一个白痴……几个月了,我假设这些值的范围是0..255(即HTML颜色值),但是它们在[0.0 .. 1.0]范围内.现在,我设置了0..255的值并将其标准化为0..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.

这篇关于为什么我不能为UINavigationBar设置自定义色调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆