可以使用Apple推荐的UX准则创建UIAlertController吗?

时间:2015-10-10 00:29:12

标签: ios xcode swift user-experience

Apple的iOS UX指南显示以下示例:

Example alert

...其中:

  • 当最可能的按钮执行非破坏性操作时,它 应该在两个按钮警报的右侧。取消按钮 这个动作应该在左边。

  • 当最可能的按钮执行破坏性操作时,它应该 在两个按钮警报左侧。取消此按钮的按钮 行动应该在右边。

来源:https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Alerts.html

但是,使用当前的iOS API(使用Swift在iOS 9上进行测试)似乎无法实现此指南。这是一次尝试。但我尝试改变添加警报操作的顺序,并更改哪个操作是.Default vs. .Cancel样式。没有任何组合可行。

@IBAction func showAlertAction(sender: AnyObject)
{
    let title = "An Alert that Offers Two Alternatives Is Easy for People to Use"

    let alertViewController = UIAlertController(title: title, message: nil, preferredStyle: UIAlertControllerStyle.Alert)

    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (alert :UIAlertAction!) -> Void in

        print("'Cancel' tapped")
    })

    alertViewController.addAction(cancelAction)

    let safeChoiceAction = UIAlertAction(title: "Safe Choice", style: UIAlertActionStyle.Default, handler: { (alert :UIAlertAction!) -> Void in

        print("'Safe Choice' tapped")
    })

    alertViewController.addAction(safeChoiceAction)

    self.presentViewController(alertViewController, animated: true, completion: nil)
}

结果:

enter image description here

0 个答案:

没有答案