簡體   English   中英

在Swift中更改UIAlertController上一個或特定按鈕的顏色

[英]Change the color of one or specific buttons on UIAlertController in Swift

我有一個UIController的操作表類型,其中顯示兩個項目,第一個是“從App注銷”,另一個是“取消”。 我想將顯示“從應用程序注銷”的按鈕的字體顏色更改為紅色,並將“取消”按鈕保留為默認顏色。 我怎樣才能做到這一點? 下面是我的代碼:

let cancelActionSheetButton = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { 
    (cancelSelected) -> Void in
    print("Cancel Selected")
}

let logoutActionSheet = UIAlertController(title:"Logout", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)

let logoutActionSheetButton = UIAlertAction(title: "Logout from App", style: UIAlertActionStyle.Default) { 
    (logoutSelected) -> Void in
}

logoutActionSheet.addAction(logoutActionSheetButton)
logoutActionSheet.addAction(cancelActionSheetButton)

self.presentViewController(logoutActionSheet, animated: true, completion:nil)

嘗試使用UIAlertActionStyle.Destructive

let logoutActionSheetButton=UIAlertAction(title: "Logout from App", style: UIAlertActionStyle.Destructive) { ... }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM