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. 如何設置URLSession斯威夫特3
- 2. 無法設置自定義視圖的限制,斯威夫特
- 3. UICollectionView自定義佈局斯威夫特
- 4. 如何斯威夫特定義MPMediaItemPropertyArtwork 3
- 5. 斯威夫特 - 如何設置的UIBarButtonItem的形象自定義類
- 6. 斯威夫特2斯威夫特3
- 7. 斯威夫特 - JSQMessagesViewController與斯威夫特
- 8. 斯威夫特更改字體編程
- 9. 如何自定義三元運營商在斯威夫特
- 10. 如何使自定義鍵盤與斯威夫特工作
- 11. 設置SKLabelNode到SKSpriteNode斯威夫特
- 12. 設置選項斯威夫特2
- 13. 自斯威夫特2
- 14. 斯威夫特後衛自
- 15. 自定義字典參考 - 斯威夫特
- 16. 斯威夫特
- 17. 斯威夫特
- 18. 斯威夫特
- 19. 斯威夫特
- 20. 斯威夫特
- 21. 斯威夫特
- 22. 斯威夫特
- 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 =歸檔文本 –