更改全局色调颜色 - iOS7/iOS8

elG*_*pha 65 uicolor tintcolor ios7

我们如何通过代码更改iOS7/iOS8上的全局色调颜色?我想更改使用此属性的多个对象,但不更改每个对象,这就是我想使用全局色调属性的原因.

Vin*_*zzz 109

只需更改应用程序委托中的UIWindow's' tintColor,它就会自动默认传递给它的所有UIView后代.

[self.window setTintColor:[UIColor greenColor]];
Run Code Online (Sandbox Code Playgroud)

  • 但是,此方法似乎并未传播到导航工具栏. (2认同)

car*_*ich 67

[[UIView appearance] setTintColor:[UIColor greenColor]];

  • 这应该是接受的答案:) (8认同)
  • 如果您需要为UIAlertView按钮而不仅仅是主应用程序窗口,这是最好的答案! (3认同)
  • `UIView`的`tintColor`没有`UI_APPEARANCE_SELECTOR`注释.这个答案是对的. (3认同)
  • 我认为这应该是正确的答案,因为它影响UIAlertView,而接受的答案不是. (2认同)
  • @Tobol在技术上是正确的。对此存在困惑,确实需要苹果公司予以澄清。iOS 5中引入了“ UIAppearance”作为一种处理全局颜色(以及更多)的方法,但是随后在iOS 7中,Apple将“ tintColor”移至了“ UIView”,并使其传播到了子视图。在[iOS 7 UI过渡指南](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TransitionGuide/AppearanceCustomization.html)中,Apple声明:“使用外观代理API设置tintColor属性在iOS 7中不受支持。” 但是它似乎仍然有效。 (2认同)

tot*_*ter 38

有两种方法可以更改全局色调颜色.由于许多上面提到你可以改变self.window.tintColor-application:didFinishLaunchingWithOptions:.

在我看来,更优雅的方式是在Storyboard 中的File Inspector中设置Global Tint,而不选择任何内容.这样你就更清洁.-application:didFinishLaunchingWithOptions:

文件检查器中的全局色调

  • 如果 Xcode 可以正常运行,那将是惊人的。可能这适用于 Xcode 345 版。今天,正如预期的那样,Xcode 在我头上胡说八道,什么也不做。我希望苹果在不久的将来从开发工具负责人的职位上解雇撒旦。 (2认同)

Ger*_*cía 12

您可以通过设置窗口的色调属性为整个应用程序指定色调颜色.为此,您可以使用类似于以下内容的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.tintColor = [UIColor purpleColor];
    return YES;
}
Run Code Online (Sandbox Code Playgroud)


Tul*_*oso 5

更新为 Swift 2.2

您可以从任何地方执行此操作,如下所示:

// Get app delegate
let sharedApp = UIApplication.sharedApplication()

// Set tint color
sharedApp.delegate?.window??.tintColor = UIColor.green()
Run Code Online (Sandbox Code Playgroud)

或者,如果您尝试从 AppDelegate 执行此操作,

self.window?.tintColor = UIColor.green()
Run Code Online (Sandbox Code Playgroud)