gpt4 book ai didi

uilabel - iOS7 UILabel 采用与窗口相同的 tintColor

转载 作者:行者123 更新时间:2023-12-03 23:03:30 26 4
gpt4 key购买 nike

我知道对于类的元素 UIButtonUIBarButtonItem他们自动假设window.tintColor作为主要颜色,如果我在应用程序中随时为窗口设置新的 tintColor,则会立即更改。

我想知道是否有任何方法可以制作UILabel元素遵循相同的模式,一旦创建,它们会自动假定其默认颜色为 window.tintColor如果更改 window.tintColor在我的应用程序运行时中的任何时间也会导致更改 UILabel自动着色?

我希望这是有道理的。

最佳答案

UILabelsUIView 的子类,因此当您在 iOS 7 中运行时,它们将具有 tintColor属性,如果他们的 tint color 设置为 nil,将从他们的父 View 继承该颜色(这是默认设置)。

来自 Apple's Documentation :

By default, a view’s tint color is nil, which means that the view uses its parent’s tint. It also means that when you ask a view for its tint color, it always returns a color value, even if you haven’t set one.



但是,您还问“是否在我的应用程序运行时中的任何时间更改 window.tintColor 也会导致自动更改 UILabel tintColour?” Apple 建议您不要在屏幕上显示项目时更改色调颜色:

In general, it’s best to change a view’s tint color while the view is offscreen.



我猜这是因为无法保证所有各种 UI 元素都会检测到 tintColor 更改并更新其可见 View 。但是, UIView documentation如果您想更新 tintColor,建议一个解决方法而您的 UILables在屏幕上:

To refresh subview rendering when this property changes, override the tintColorDidChange method.



所以请务必调用 tintColorDidChange在当前屏幕上的任何 View 上,其色调颜色应在 tintColor 时更新他们的父 View 发生变化。

但是你的 UILabel 为什么不呢? ' 更新他们的颜色?

所以以上帮助你设置和更新你的各种 tintColor的,但你没有看到任何效果 - 为什么?

嗯,这与 Apple 设计 Tint 所要指示的内容有关。来自 Human Interface Guidelines :

color gives users a strong visual indicator of interactivity



Apple 摆脱了交互元素周围的边框和渐变,并用颜色代替了它们 - 特别是 tintColor . tintColor 背后的整个想法是用户可以点击的东西得到它,而他们不能点击的东西没有。
UILabel不是一个交互元素——它是一个文本描述——所以苹果会让你设置一个 tintColor在它上面(因为任何 UIView 有一个 tintColor )但是设置它 tintColor不会改变它的绘制方式。

那你该怎么办? 首先,请注意,让更多的按钮呈现淡色对于您的应用程序来说可能是一个糟糕的 UI 选择 - iOS 7 用户和 Apple 应用程序审阅者都希望遵循这些规则。

所以你是不是被迫保留你的 UILabel那么没有颜色呢?

不——特别是如果你做的事情“正确”。苹果解释说:

In a content area, add a button border or background only if necessary. Buttons in bars, action sheets, and alerts don’t need borders because users know that most of the items in these areas are interactive. In a content area, on the other hand, a button might need a border or a background to distinguish it from the rest of the content.



我建议您考虑应用程序的 UI。如果您真的希望您的非交互元素具有相同的 tintColor作为您的交互元素,然后确保您使用更多的东西,例如边框或背景颜色,以便您的用户(和 Apple 应用程序审阅者)知道什么是可点击的,什么是不可点击的。

至于如何更新颜色,您可以手动设置 textColor属性是您想要的任何颜色,否则您需要创建自己的 UILabel 的子类覆盖 - (void)tintColorDidChange更新 textColor发送通知时的属性 - 允许您拥有 UILabel其文本更新以匹配 tintColor它的 parent 。

我希望这有帮助!

关于uilabel - iOS7 UILabel 采用与窗口相同的 tintColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19121313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com