我的提示框正在使用自定义背景&白色文字除了我似乎无法在我的行为中获得白色文字是&否(来自addAction语句)。当我使用属性字符串作为警告框标题&时,白色文本确实显示用途。消息。
@IBAction func deletePlayer1(sender: UIButton) {
//set player1Name to nil
let alert = UIAlertController(title: "Delete Player", message: "Do you want to delete this player?", preferredStyle: .Alert)
// set font size and color for message in alert box
let attributedString = NSAttributedString(string: "Do you want to delete this player?", attributes: [
NSFontAttributeName : UIFont.systemFontOfSize(15),
NSForegroundColorAttributeName : UIColor.whiteColor() ])
alert.setValue(attributedString, forKeyPath: "attributedMessage")
// set font size and color for title of alert box
let attributedString1 = NSAttributedString(string: "Delete Player", attributes: [
NSFontAttributeName : UIFont.systemFontOfSize(15),
NSForegroundColorAttributeName : UIColor.whiteColor() ])
alert.setValue(attributedString1, forKeyPath: "attributedTitle")
// set the background color and add rounded labels for the alert box
let subView = alert.view.subviews.first! as UIView
let contentView = subView.subviews.first! as UIView
contentView.backgroundColor = UIColor(red: 64.0/255.0, green: 128.0/255.0, blue: 255.0/255.0, alpha: 1.0)
contentView.layer.cornerRadius = 10
alert.addAction(UIAlertAction(title: "Yes", style: .Default, handler: {(alertAction: UIAlertAction!) -> Void in
// set font size and color for title of action text in alert box - this is NOT working
let attributedString2 = NSAttributedString(string: "Yes", attributes: [
NSFontAttributeName : UIFont.systemFontOfSize(15),
NSForegroundColorAttributeName : UIColor.whiteColor() ])
alert.setValue(attributedString2, forKeyPath: "attributedTitle")
print("you press yes")
}))
alert.addAction(UIAlertAction(title: "No", style: .Default, handler: {(alertAction: UIAlertAction!) -> Void in
print("you press no")
}))
self.presentViewController(alert, animated: true) { () -> Void in
}
答案 0 :(得分:0)
您可以通过将警报视图tintColor设置为白色来完成此操作。
alert.view.tintColor = .whiteColor()