【问题标题】:How to change one UIAlertAction text color in a UIAlertController如何在 UIAlertController 中更改一种 UIAlertAction 文本颜色
【发布时间】:2016-03-10 00:54:46
【问题描述】:

如何更改 UIAlertController 中一个 UIAlertAction 而不是所有操作按钮的文本颜色。

这是我的 UIAlertController 代码:我想将 Delete UIAlertAction 文本颜色更改为红色。

//Alert to select more method
func moreAlert()
{           
    let optionMenu = UIAlertController(title: "Mere", message: "", preferredStyle: UIAlertControllerStyle.ActionSheet)

    let Edit = UIAlertAction(title: "Rediger", style: .Default, handler: { action in

    })


    let Delete = UIAlertAction(title: "Slet", style: .Default, handler: { action in

    })

    let cancelAction = UIAlertAction(title: "Annullere", style: .Cancel, handler: { action in        
        print("Cancelled")
    })

    optionMenu.addAction(Edit)            
    optionMenu.addAction(Delete)            
    optionMenu.addAction(cancelAction)


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

【问题讨论】:

    标签: swift xcode7 uialertcontroller uialertaction


    【解决方案1】:

    在您的 Delete UIAlertAction 的初始化程序中使用参数 style: .destructive

    【讨论】:

      【解决方案2】:

      尝试在 presentViewController 之前将其添加到您的 alertController 中

      optionMenu.view.tintColor = UIColor.redColor()
      

      【讨论】:

      • 这会影响整个警报控制器,而不仅仅是问题中要求的一项操作。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-01
      相关资源
      最近更新 更多