首页 > 解决方案 > 为什么当我单击 UIBarButtonItem 时它会调整大小?

问题描述

每当我单击具有 unicode 标题以显示 cog 符号的 UIBarButtonItem 时,它会调整大小并变小。这是代码:

let settings = UIBarButtonItem(title: NSString(string: "\u{2699}\u{0000FE0E}") as String, style: .plain, target: self, action: #selector(show_settings))
let font = UIFont.systemFont(ofSize: 28)
let attributes = [NSAttributedStringKey.font : font]
settings.setTitleTextAttributes(attributes, for: .normal)

这是我单击它时的样子: UIBarButtonItem 调整大小错误

标签: iosswift

解决方案


为突出显示的状态以及以下设置 TitleAttributes:

 let settings = UIBarButtonItem(title: NSString(string: "\u{2699}\u{0000FE0E}") as String, style: .plain, target: self, action: #selector(show_settings))
        let font = UIFont.systemFont(ofSize: 28)
        let attributes = [NSAttributedStringKey.font : font]
        settings.setTitleTextAttributes(attributes, for: .normal)
        settings.setTitleTextAttributes(attributes, for: .highlighted)

在此处输入图像描述

希望这会帮助你:)


推荐阅读