UIAlertController tint color defaults to blue on h

2019-02-07 17:03发布

I'm use the following code to present a UIAlertController action sheet with the item text as red. I've used the tint property to set the color.

UIAlertController *alertController = [UIAlertController
                                      alertControllerWithTitle:nil
                                      message:nil
                                      preferredStyle:UIAlertControllerStyleActionSheet];
alertController.view.tintColor = [UIColor redColor];

The text color seems to be defaulting to blue on highlight or selection. Is this normal and how do I stop this?

11条回答
相关推荐>>
2楼-- · 2019-02-07 17:21

UIAlertController is availabel iOS 8 and later , thus there is a bug for devices with older version. There's no problem for devices with corresponding or higher version.

查看更多
迷人小祖宗
3楼-- · 2019-02-07 17:24

You can also change the app tint color in appdelegate.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.tintcolor = [UIColor yellowColor];
    return YES;
}

works perfect for me.

查看更多
家丑人穷心不美
4楼-- · 2019-02-07 17:28

I am still confused what you want to achieve. But you can try the Apple's way of creating Destructive buttons(by default text color is red).

The code where you are creating UIAlertActions don't use the Default style for the buttons you want in red color. Instead use UIAlertActionStyleDestructive. Sample Code :

UIAlertAction* cancel = [UIAlertAction
                         actionWithTitle:@"Cancel"
                         style:UIAlertActionStyleDestructive
                         handler:^(UIAlertAction * action)
                         {
                             [view dismissViewControllerAnimated:YES completion:nil];

                         }];
查看更多
倾城 Initia
5楼-- · 2019-02-07 17:33

Update for Swift 4, Xcode 9

private static func setupAppearanceForAlertController() {
    let view = UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self])
    view.tintColor = .black
}
查看更多
乱世女痞
6楼-- · 2019-02-07 17:33

You can change button colour like this

UIAlertAction* button = [UIAlertAction
                              actionWithTitle:@"Delete Profile"
                              style:UIAlertActionStyleDefault
                              handler:^(UIAlertAction * action)
                              {
                                  //Add Action.
                              }];
[button setValue:[UIColor redColor] forKey:@"titleTextColor"];

By Using this line [button setValue:[UIColor redColor] forKey:@"titleTextColor"]; You can change the button colour of your action sheet

查看更多
beautiful°
7楼-- · 2019-02-07 17:33

Set your tint color in traitCollectionDidChange in a subclass of UIAlertController.

override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {
    super.traitCollectionDidChange(previousTraitCollection)
    self.view.tintColor = UIColor.redColor()
}
查看更多
登录 后发表回答