问题描述
我知道对于类 UIButton
和 UIBarButtonItem
的元素,它们会自动假设窗口。 tintColor
作为主要颜色,如果我在应用程序中随时将新的tintColor设置为窗口,则会立即更改。
I know that for elements of classes UIButton
and UIBarButtonItem
they automatically assume window.tintColor
as the main colour, which results of an immediate change in case I set a new tintColor to window at any time in the app.
我想知道是否有任何方法可以使 UILabel
元素遵循相同的模式,一旦创建,它们会自动将其默认颜色设置为 window.tintColor
如果在我的应用运行时内任何时候更改 window.tintColor
,也会导致更改 UILabel
tintColour自动?
I was wondering if there is any way to make UILabel
elements to follow the same pattern, where once created they automatically assumer its default colour as window.tintColor
and if changing window.tintColor
at any time within my app runtime would also result in changing the UILabel
tintColour automatically?
我希望这是有道理的。
推荐答案
UILabels
是 UIView
的子类,因此当你在iOS 7中运行时,它们将具有 tintColor
属性,如果它们的色调颜色设置为 nil
(这是defa),它将从父视图继承该颜色ult)。
UILabels
are a subclass of UIView
, so when you are running in iOS 7 they will have a tintColor
property and will inherit that color from their parent view if their tint color is set to nil
(which is default).
来自:
但是,您还会问在我的应用运行时内是否随时更改window.tintColor也会导致自动更改UILabel tintColour? Apple建议您在屏幕上显示项目时不要更改色调颜色:
However, you also ask "if changing window.tintColor at any time within my app runtime would also result in changing the UILabel tintColour automatically?" Apple advises you to not change the tint color when items are on screen:
我猜这是因为没有保证所有各种UI元素都会检测到tintColor更改和更新他们的可见视图。但是,建议在您的<$ c时更新 tintColor
的解决方法屏幕上显示$ c> UILables :
I would guess this is because there is no guarentee that all the various UI elements will detect the tintColor change and update their visible views. However, the UIView
documentation suggests a workaround if you want to update tintColor
while your UILables
are on screen:
所以只需确保在当前屏幕上的任何视图上调用 tintColorDidChange
当其父视图的 tintColor
更改时,其色调颜色应更新。
So just make sure to call tintColorDidChange
on any views currently on screen whose tint color should update when the tintColor
of their parent view changes.
但为什么不你的 UILabel
更新他们的颜色?
But why don't your UILabel
's update their color?
所以上面的内容可以帮助你设置和更新你的各种颜色 tintColor
's,但你没有看到任何效果 - 为什么?
So the above helps you set and update your various tintColor
's, but you're not seeing any effect - why?
这与什么有关Apple设计了Tint t o表明。来自:
Well that has to do with what Apple designed Tint to indicate. From the Human Interface Guidelines:
Apple摆脱了交互元素周围的边框和渐变,并用颜色替换它们 - 特别是 tintColor
。 tintColor
背后的整个想法是用户可以点击它的东西,而他们无法点击的东西不会。
Apple got rid of borders and gradients around interactive elements and replaced them with color - specifically tintColor
. The whole idea behind tintColor
is that things users can tap on get it, and things they can't tap on don't.
UILabel
不是一个交互元素 - 它是一个文本描述 - 所以Apple会让你设置一个 tintColor
就可以了(因为任何 UIView
有一个 tintColor
)但设置 tintColor
不会改变它的绘制方式。
UILabel
is not an interactive element - it is a text description - and so Apple will let you set a tintColor
on it (as any UIView
has a tintColor
) but setting that tintColor
will not change how it is drawn.
那么你应该怎么做?首先要注意的是,制作超过只是按钮采用色调颜色可能是您的应用程序的一个糟糕的UI选择 - iOS 7用户和Apple应用程序审阅者都期望遵循这些规则。
So what should you do? First, be aware that making more than just buttons take on the tint color could be a poor UI choice for your app - iOS 7 users and Apple app reviewers both will be expecting those rules to be followed.
所以您是否被迫保持 UILabel
免于颜色?
So are you forced to keep your UILabel
free from color then?
否 - 特别是如果你做的事情正确 。 Apple解释说:
No - especially if you do things "right". Apple explains:
我建议你考虑你的应用程序的用户界面。如果您真的希望非互动元素具有相同的 tintColor
作为您的互动元素,那么请确保您使用更多内容,例如边框或背景颜色,以便您的用户(和Apple应用程序审阅者)知道什么是可点击的,什么不是。
I would suggest you consider the UI of your app. If you really want your non-intereactive elements to have the same tintColor
as your interactive elements, then make sure you use something more, like a border or background color, so your users (and Apple app reviewers) know what is clickable and what is not.
关于如何更新颜色,您可以手动设置 textColor
属性是你想要的颜色,或者你需要创建自己的 UILabel
的子类来覆盖 - (void)tintColorDidChange
在发送通知时更新 textColor
属性 - 允许你拥有 UILabel
其文本更新以匹配其父级的 tintColor
。
As to how you should update the colors, you can either manually set the textColor
property to be whatever color you want, or you'll need to make your own subclass of UILabel
that overrides - (void)tintColorDidChange
to update the textColor
property when notifications are sent out - allowing you to have a UILabel
whose text updates to match the tintColor
of its parent.
我希望这有帮助!
这篇关于iOS7 UILabel采用相同的tintColor作为窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!