Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在Swift中设置UIAlertAciton的自定义字体_Ios_Swift_Uialertcontroller_Uialertaction - Fatal编程技术网

Ios 如何在Swift中设置UIAlertAciton的自定义字体

Ios 如何在Swift中设置UIAlertAciton的自定义字体,ios,swift,uialertcontroller,uialertaction,Ios,Swift,Uialertcontroller,Uialertaction,参考表格: 代码: let alertcontroller = UIAlertController(title: "try", message: "now", preferredStyle: .alert) let action = UIAlertAction(title: "Some title", style: .destructive, handler: nil) let attributedText = NSMutableAttributedString(string: "Ne

参考表格:

代码:

 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)
输出:


如果您在
操作中使用了
属性文本
,我认为这是不可能的,我们只能添加alertcontroller而不是UIAlertActionguard let label=(Camera.value(forKey:“\u representer”)作为任何对象)作为?UILabel else{return}label.attributedText=attributedText其不工作attributedText是UIAlertController的私有属性,Apple不允许更改该属性。它将工作一段时间,但苹果将在提交时拒绝。在上面的链接中,文本颜色正在变化,但我不能添加自定义font@AmuthaKumari-
警报操作
仅允许更改
文本颜色
其他我们无法更改的内容handle@Anbu.Karthik以下是在中设置自定义字体的解决方案swift@AmuthaKumari-hey sister,是定制的UIViewController,默认情况下我们无法处理UIAlertcontroller,如果我们需要定制的话
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)