Is it possible to edit UIAlertAction title font size and style?

前端 未结 2 1253
走了就别回头了
走了就别回头了 2021-01-03 02:36

Now that iOS8 deprecated UIActionsheet and UIAlertview the customization working on iOS7 is not taking effect anymore. So far the only customizatio

2条回答
  •  暖寄归人
    2021-01-03 02:42

    It is possible to change alert action's font using private APIs. It may get you app rejected, I have not yet tried to submit such code.

    let alert = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)
    
    let action = UIAlertAction(title: "Some title", style: .Default, handler: nil)let attributedText = NSMutableAttributedString(string: "Some title")
    
    let range = NSRange(location: 0, length: attributedText.length)
    attributedText.addAttribute(NSKernAttributeName, value: 1.5, range: range)
    attributedText.addAttribute(NSFontAttributeName, value: UIFont(name: "ProximaNova-Semibold", size: 20.0)!, range: range)
    
    alert.addAction(action)
    
    presentViewController(alert, animated: true, completion: nil)
    
    // this has to be set after presenting the alert, otherwise the internal property __representer is nil
    guard let label = action.valueForKey("__representer")?.valueForKey("label") as? UILabel else { return }
    label.attributedText = attributedText
    

提交回复
热议问题