要设置自定义颜色和字体子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我已经改变了文字颜色为红色的行动表项目。哪些工作正常,但是当您突出显示或选择操作表项时。它默认为蓝色。我希望它保持红色。 –