我想更改整个应用程序的所有UILabel的文本颜色,我该怎么做。是否有任何简单的方法来更改标签颜色。

我试过了,但是我想改变每个类(class)写这段代码

for( UIView *view in [testScroll subviews])
    {
        if([view isKindOfClass:[UILabel class]])
        {
            [(UILabel *)view setTextColor:[UIColor whiteColor]];

        }
        else if([view isKindOfClass:[UIView class]])

    }

有没有人有简单的方法。

最佳答案

好吧,如果您的目标是iOS 5+,那么您可以做到这一点非常简单(在您的appdelegate内部):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //...

    //This color will affect every label in your app
    [[UILabel appearance] setTextColor:[UIColor redColor]];

    //...

    return YES;
}

这是有效的,因为UILabel符合UIAppearance协议(protocol),因此您可以像这样自定义符合协议(protocol)的任何类。有关此here is a nice tutorial to get you startedhere is Apple's docs on the protocol的更多信息

关于objective-c - 更改整个项目的UILabel的文本颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16937110/

10-11 00:32
查看更多