在 iOS 中使用 Swift 更改 UIAlertAction 的 UIAlertController 按钮标题的字体大小


let alertController: UIAlertController = UIAlertController(title: "Alert", message: nil, preferredStyle: .alert)
            let customActionButton: UIAlertAction = UIAlertAction(title: "Custom", style: .default) { action -> Void in
            }
            let attrString: NSAttributedString = NSAttributedString(string: "Custom", attributes: [NSFontAttributeName: UIFont.init(name: "Roboto-Regular", size: 17.0)!])
            customActionButton.setValue(attrString, forKey: "attributedTitle")
            alertController.addAction(customActionButton)
            present(alertController, animated: true, completion: nil)

任何人都可以告诉我是否可以在 swift 中更改警报操作按钮

没有可用于执行此操作的公共 API。即使您能够通过私有 API 实现这一点,也会导致应用程序在审核时被拒绝。

您可以查看NSHipster的这篇文章,其中介绍了UIAlertController的基本样式:http://nshipster.com/uialertcontroller/

此外,如果您希望更改警报中的字体颜色。只需在警报中更改视图的色调颜色即可。

alert.view.tintColor = UIColor.green /// where alert is UIAlertController object

最新更新