我试图通过一些绿色操作来实现 View ,并让所选操作在 UIAlertController 中以粗体显示。其中一个操作(即关闭按钮)必须与其他操作分开,并用红色着色。
我正在尝试使用 .cancel 允许显示关闭按钮的样式添加它们,但它是粗体,但是是绿色的。 我该如何实现这一目标?
预期 View :
我当前的代码:
let alertController
= UIAlertController(title: nil,
message: nil,
preferredStyle: .actionSheet)
let sortByDateAction = UIAlertAction(title: "По дате",
style: .default,
handler: {(action: UIAlertAction!) in
if self.sortBy != "date" {
self.page = 1
self.sortBy = "date"
self.loadTenders()
}
})
let moreExpensiveSortAction = UIAlertAction(title: "Дороже",
style: .destructive,
handler: {(action: UIAlertAction!) in
if self.sortBy != "priceHigh" {
self.page = 1
self.sortBy = "priceHigh"
self.loadTenders()
}
})
let cheaperSortAction = UIAlertAction(title: "Дешевле",
style: .default,
handler: {(action: UIAlertAction!) in
if self.sortBy != "priceLow" {
self.page = 1
self.sortBy = "priceLow"
self.loadTenders()
}
})
alertController
.addAction(sortByDateAction)
alertController
.addAction(moreExpensiveSortAction)
alertController
.addAction(cheaperSortAction)
alertController.preferredAction = sortByDateAction
alertController
.addAction(UIAlertAction(title: "Dismiss",
style: .cancel,
handler: nil))
最佳答案
let cancelAlert = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler:nil)
cancelAlert.setValue(UIColor.red, forKey: "titleTextColor")
alertController.addAction(cancelAlert)
试试这个代码。
关于ios - 如何在 UIAlertAction 中显示选定的操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44404899/