gpt4 book ai didi

swift - 在 Swift 中使用 UIAlertController 更改警报的标题和消息字体

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:02 27 4
gpt4 key购买 nike

我正在尝试更改使用 UIAlertController 显示的警报的标题和消息字体我正在尝试使用 NSAttributedStirng,但它给出了编译器错误,即无法采用 NSAttributed 字符串代替 Stirng我尝试了类似于 this 的东西

var title_attrs = [NSFontAttributeName : CustomFonts.HELVETICA_NEUE_MEDIUM_16]
var msg_attrs = [NSFontAttributeName : CustomFonts.HELVETICA_NEUE_REGULAR_14]
var title = NSMutableAttributedString(string:"Done", attributes:title_attrs)

var msg = NSMutableAttributedString(string:"The job is done ", attributes:msg_attrs)
let alertController = UIAlertController(title: title, message: title , preferredStyle: UIAlertControllerStyle.Alert)

有人可以指导我如何实现这一目标吗?

最佳答案

Swift 3 版本:

extension UIAlertController {
func changeFont(view: UIView, font:UIFont) {
for item in view.subviews {
if item.isKind(of: UICollectionView.self) {
let col = item as! UICollectionView
for row in col.subviews{
changeFont(view: row, font: font)
}
}
if item.isKind(of: UILabel.self) {
let label = item as! UILabel
label.font = font
}else {
changeFont(view: item, font: font)
}

}
}

open override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
let font = YOUR_FONT
changeFont(view: self.view, font: font! )
}
}

关于swift - 在 Swift 中使用 UIAlertController 更改警报的标题和消息字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26777189/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com