let alertcontroller = UIAlertController(title: "try", message: "now", preferredStyle: .alert)
let action = UIAlertAction(title: "Some title", style: .destructive, handler: nil)
let attributedText = NSMutableAttributedString(string: "New User")
let range = NSRange(location: 0, length: attributedText.length)
attributedText.addAttribute(NSKernAttributeName, value: 1.5, range: range)
attributedText.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 25.0), range: range)
action.setValue(UIColor(hex: 0xFF9B05),forKey: "titleTextColor")
alertcontroller.addAction(action)
0
A
回答
0
参考形式:Refer from Here.
代码:
let alertController = UIAlertController(title: "Alert Title", message: "This is testing message.", preferredStyle: UIAlertControllerStyle.Alert)
// Background color.
let backView = alertController.view.subviews.last?.subviews.last
backView?.layer.cornerRadius = 10.0
backView?.backgroundColor = UIColor.yellowColor()
// Change Title With Color and Font:
let myString = "Alert Title"
var myMutableString = NSMutableAttributedString()
myMutableString = NSMutableAttributedString(string: myString as String, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 18.0)!])
myMutableString.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: NSRange(location:0,length:myString.characters.count))
alertController.setValue(myMutableString, forKey: "attributedTitle")
// Change Message With Color and Font
let message = "This is testing message."
var messageMutableString = NSMutableAttributedString()
messageMutableString = NSMutableAttributedString(string: message as String, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 18.0)!])
messageMutableString.addAttribute(NSForegroundColorAttributeName, value: UIColor.greenColor(), range: NSRange(location:0,length:message.characters.count))
alertController.setValue(messageMutableString, forKey: "attributedMessage")
// Action.
let action = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)
action.setValue(UIColor.orangeColor(), forKey: "titleTextColor")
alertController.addAction(action)
self.presentViewController(alertController, animated: true, completion: nil)
OUTPUT:
+0
在上面的链接文字颜色正在改变提醒行动,但我不能添加自定义字体 –
+0
@AmuthaKumari - '警报行动'只具有文字'文字颜色'otherthing我们无法处理 –
+0
谢谢你的回复 –
相关问题
- 1. 设置XlsxReaderWriter - 斯威夫特
- 2. Xcode 6中的自定义字体 - 斯威夫特不工作
- 3. 如何设置URLSession斯威夫特3
- 4. 自定义UIView类 - 斯威夫特
- 5. 自定义协议斯威夫特
- 6. UICollectionView自定义布局斯威夫特
- 7. 无法设置自定义视图的限制,斯威夫特
- 8. 如何斯威夫特定义MPMediaItemPropertyArtwork 3
- 9. 斯威夫特转换斯威夫特
- 10. 斯威夫特2斯威夫特3
- 11. 斯威夫特 - JSQMessagesViewController与斯威夫特
- 12. 斯威夫特 - 如何设置的UIBarButtonItem的形象自定义类
- 13. 斯威夫特更改字体编程
- 14. 斯威夫特UIView的自定义位置
- 15. 斯威夫特 - 如何在自定义按键敲击时AlertController
- 16. 如何使自定义键盘与斯威夫特工作
- 17. 如何自定义三元运营商在斯威夫特
- 18. 自斯威夫特2
- 19. 斯威夫特后卫自
- 20. 设置Cookie与斯威夫特3
- 21. 设置SKLabelNode到SKSpriteNode斯威夫特
- 22. 设置选项斯威夫特2
- 23. 斯威夫特
- 24. 斯威夫特
- 25. 斯威夫特
- 26. 斯威夫特
- 27. 斯威夫特
- 28. 斯威夫特
- 29. 斯威夫特
- 30. 斯威夫特
哪里我在'action'中使用了'attributedText' –
我认为不可能,我们可以只添加alertcontroller而不是UIAlertAction –
guard let label =(Camera.value(forKey:“__representer”)as AnyObject)as? UILabel其他{返回} label.attributedText =归档文本 –