2017-05-26 3 views
0
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

wo Du hast den 'attributiedText' in' action' verwendet. –

+0

ich denke s nicht möglich, wir können alarmcontroller nur nicht hinzufügen UIAlertAction –

+0

guard label = (Camera.value (forKey: "__presententer") als AnyObject) as? UILabel else {return} label.attributedText = attributiedText –

Antwort

0

Referenz Form einzustellen: Refer from Here.

Code:

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:

enter image description here

+0

In den obigen Link Text Farbe in Alert-Aktion, aber ich kann nicht die benutzerdefinierte Schriftart hinzufügen –

+0

@AmuthaKumari - "Alert-Aktion" hat nur den Wert für chnage die 'text colour' andere können wir nicht behandeln –

+0

Vielen Dank für Ihre Antwort –

Verwandte Themen