简体   繁体   English

更改按钮标题 iOS 15

[英]Change Button Title in iOS 15

I am using new button configuration style as introduce in iOS 15. It works great!我正在使用 iOS 中介绍的新按钮配置样式 15。效果很好!

But when I try to change the title, it is also change the font.但是当我尝试更改标题时,它也会更改字体。

Ref similar issue: uibutton.setTitle change text without changing font size参考类似问题: uibutton.setTitle change text without changing font size

I don't want to go back to old style:(我不想 go 回到旧样式:(

My try:我的尝试:

var config = self?.btnNext.configuration
    config?.title = "New Title"
self?.btnNext.updateConfiguration()

Thank you,谢谢,

Try using an attributedTitle so you can set the font:尝试使用 attributedTitle 以便您可以设置字体:

config?.attributedTitle = AttributedString("your new title", 
attributes: AttributeContainer([
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20.0), NSAttributedString.Key.foregroundColor: .black]))

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM