要設置自定義顏色和字體子UIAlertController
這個樣子。
import UIKit
class StyledAlertController: UIAlertController {
private var cancelText:String?
override func viewDidLoad() {
super.viewDidLoad()
view.tintColor = YourColor
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
findLabel(view)
}
private func findLabel(scanView: UIView!) {
if (scanView.subviews.count > 0) {
for subview in scanView.subviews {
if let label:UILabel = subview as? UILabel {
if (cancelText != nil && label.text == cancelText!) {
dispatch_async(dispatch_get_main_queue(),{
label.textColor = YourColor
label.tintColor = YourColor
})
}
let font:UIFont = UIFont(name: YourFont, size: label.font!.pointSize)!
label.font = font
}
findLabel(subview)
}
}
}
}
使用像這樣(像通常那樣)
let StyledAlertController = StyledAlertController(title: "My Title", message: "My Message", preferredStyle: .ActionSheet)
let cancelAction:UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in
print("Cancel Action Click")
}
actionSheetController.addAction(cancelAction)
let anotherAction:UIAlertAction = UIAlertAction(title: "Another Action", style: .Default) { action -> Void in
print("Another Action Click")
}
actionSheetController.addAction(anotherAction:UIAlertAction)
presentViewController(actionSheetController, animated: true, completion: nil)
要改變文字顏色爲紅色或背景色爲紅色在所有模式 –
它有點不清楚你想要達到的目標,但這裏看看,我想你會在這個線程中找到答案http://stackoverflow.com/questions/4248400/uiactionsheet-buttons-color – deimus
@deimus我已經改變了文字顏色爲紅色的行動表項目。哪些工作正常,但是當您突出顯示或選擇操作表項時。它默認爲藍色。我希望它保持紅色。 –