[英]String of different size for UIButton titlelabel
我正在尝试将按钮操作的标题置于警报中,如下所示
let formattedString = NSMutableAttributedString()
formattedString.append(NSAttributedString(string: "Text is small" ,
attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 8.0)]))
formattedString.append(NSAttributedString(string: "Text is large"))
在 UIAlertcontroller 操作 UIButton
.addAction(action: AABlurAlertAction(title: formattedString, style: AABlurActionStyle.modern)
但它拒绝接受NSMutableAttributedString传递给 title 参数
抛出错误
Cannot convert value of type 'NSMutableAttributedString' to expected argument type 'String?'
尝试setAttributedTitle()而不是setTitle()
button.setAttributedTitle(formattedString, for: .normal)
您只需要更改 AABlurAlertAction 类中的一些代码
self.setTitle(title, for: UIControlState.normal)
将其替换为
self.setAttributedTitle(title, for: UIControlState.normal)
并替换
public init(title: String?, style: AABlurActionStyle, handler: ((AABlurAlertAction) -> Void)?) {
和
public init(title: NSAttributedString?, style: AABlurActionStyle, handler: ((AABlurAlertAction) -> Void)?) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.