【问题标题】:How to change Action Sheet Default action color only?如何仅更改操作表默认操作颜色?
【发布时间】:2015-10-23 17:25:46
【问题描述】:

我有一个包含一个默认操作和一个取消操作的操作表。如何仅更改默认操作文本颜色?

var refreshAlert = UIAlertController(title: "", message: "Are you sure you want to clear the entire message history? \n This cannot be undone.", preferredStyle: UIAlertControllerStyle.ActionSheet)

refreshAlert.addAction(UIAlertAction(title: "Clear message history", style: .Default, handler: { (action: UIAlertAction!) in
    print("Handle Ok logic here")
    // how to change this text color to red?
}))

refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: { (action: UIAlertAction!) in
    print("Handle Cancel Logic here")
}))

【问题讨论】:

    标签: ios swift uiactionsheet


    【解决方案1】:

    你不能。而是更改您的方法,如下所示:Apple 为破坏性按钮提供了红色。

    refreshAlert.addAction(UIAlertAction(title: "Clear message history", style: .Destructive, handler: { (action: UIAlertAction!) in
        print("Voila !! button color is changed")
    }))
    

    【讨论】:

    • OP 要求更改使用.Default 样式定义的警报操作颜色。
    【解决方案2】:

    我认为没有直接的方法可以做到这一点。但是,您可以在这里应用一个丑陋的技巧:

    1. 创建与UIAlertController 操作表样式按钮大小完全相同的图像。
    2. 确保图片看起来与您希望 UI 看起来完全一样,包括文字和颜色。
    3. 将该图像作为image 属性传递给您的Default 操作,如下所示:

    ->

    let defaultAction = UIAlertAction(title: "Clear message history", style: .Default, handler: { (action: UIAlertAction!) in
            print("Handle Ok logic here")
            // how to change this text color to red?
    })
    
    let image = UIImage(named: "myButtton.png")
    defaultAction.setValue(image, forKey: "image")
    alertController.addAction(defaultAction)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-01
      • 1970-01-01
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多