ios - 有什么方法可以使 UIAlertController 的所有按钮/操作中的文本变为粗体?

标签 ios swift

我有一个要求,UIAlertController 的按钮中的文本应该为每个按钮设置为粗体(与标准的 iOS 行为相反,该行为分配了取消样式的按钮是粗体,或者 preferredAction 具有been set is bold.要求所有按钮文本都应该是粗体)。

有没有办法使用 UIAlertController 实现这一点?或者我会被迫使用 UIView 创建自定义对话框吗?

过去有很多关于使用属性字符串操作 UIAlertController 的正文文本的问题/答案,但我没有找到任何可以对 UIAlertController 的操作按钮文本进行等效操作的方法。

最佳答案

UIAlertController 上的按钮属于 UIAlertActionUIAlertAction 的任何属性都没有任何 setter 方法可用,因此您无法将按钮文本更改为粗体。

即使title 也必须是String 类型,它不接受NSAttributedString。因此,您应该使用 UIView 使用自定义对话框。

UIAlertAction 的 Apple 类引用:

@available(iOS 8.0, *)
open class UIAlertAction : NSObject, NSCopying {

    public convenience init(title: String?, style: UIAlertActionStyle, handler: ((UIAlertAction) -> Swift.Void)? = nil)

    open var title: String? { get }

    open var style: UIAlertActionStyle { get }

    open var isEnabled: Bool
}

关于ios - 有什么方法可以使 UIAlertController 的所有按钮/操作中的文本变为粗体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49823093/

相关文章:

ios - 在 iOS 上设置 <select> 的样式

ios - UITableViewCell、图像和纵横比

ios - 从 FIRRemoteConfigValue 转换为不相关的类型 String 总是失败 : Firebase, Swift

ios - 有没有办法在用户每次打开应用程序时不重新下载图像?

ios - 将视频保存到我的相机胶卷返回错误 : The operation couldn’t be completed.(Cocoa 错误 -1。)

ios - 如何复制 Instagram 或 Facebook 捏合以在 UITableViewCell 中放大和拖动图像上的手势?

ios - 将 xcarchive 转换为 IPA 时出错 - 单包归档 + 缺少 plist 方法值

ios - 如何从通过 Show Detail segue 推送的堆栈中手动弹出 View Controller ?

ios - 当 Tableview 中嵌入了多个 Collection View 时,如何进行 Segue?

swift - 创建一个用于执行动画的等待队列