I\'m use the following code to present a UIAlertController action sheet with the item text as red. I\'ve used the tint property to set the color.
UIAlertCont
To set custom color and font subclass UIAlertController like this.
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)
}
}
}
}
Use like this (as you normally would)
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)