iOS UIAlertController bold button changed in 8.3

2019-01-21 18:56发布

UIAlertController with two buttons with styles set:

UIAlertActionStyle.Cancel
UIAlertActionStyle.Default

in iOS 8.2, the Cancel button is non-bold and Default is bold. In iOS 8.3 they have switched round

You can see it Apple's own apps e.g., Settings > Mail > Add Account > iCloud > enter invalid data, then it shows like this on 8.3:

Unsupported Apple ID

Learn More (bold) OK (non-bold)

whereas it was the other way round for 8.2.

Any workaround to make it like 8.2 again. Why has it changed?

3条回答
祖国的老花朵
2楼-- · 2019-01-21 19:08

From iOS 9 you can set the preferredAction value to the action which you want the button title to be bold.

    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
    let OKAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
    alert.addAction(cancelAction)
    alert.addAction(OKAction)
    alert.preferredAction = OKAction
    presentViewController(alert, animated: true) {}

The OK button which is on the right will be in bold font.

查看更多
小情绪 Triste *
3楼-- · 2019-01-21 19:11

This is an intentional change to the SDK. I have just had a response from Apple to this radar on the issue, stating that:

This is an intentional change - the cancel button is to be bolded in alerts.

I can't find anything in the various change logs mentioning this, unfortunately.

So, we'll need to make changes to our apps in places to make some things make sense.

查看更多
Root(大扎)
4楼-- · 2019-01-21 19:11

I just checked in iOS 8.2: a first added button is non-bold and a second added button is bold. With this code a cancel button will be bold:

[alertController addAction:[UIAlertAction actionWithTitle:@"Ok"
                                                    style:UIAlertActionStyleDefault
                                                  handler:nil]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel"
                                                    style:UIAlertActionStyleCancel
                                                  handler:nil]];

And with this code a default button will be bold:

[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel"
                                                    style:UIAlertActionStyleCancel
                                                  handler:nil]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Ok"
                                                    style:UIAlertActionStyleDefault
                                                  handler:nil]];

I can't check in iOS 8.3 now but this behavior can be a reason.

查看更多
登录 后发表回答