ios - 快速点击条形按钮项目时 UIFont 发生变化

标签 ios swift uibarbuttonitem

我为 barButtonItem、UIColor、自定义字体设置了 setTitleTextAttributes。 当我点击 barButton 时,在我按住 barButton 的那段时间里,字体更改为系统字体,在我放开 barButton 后它返回自定义字体。我不使用 tintColor 设置。为什么会这样?

谁能帮帮我?

这是我设置属性的方式:

@IBOutlet weak var saveBarButton: UIBarButtonItem! { 
    didSet {
        saveBarButton.title = "SAVE"
        saveBarButton.setTitleTextAttributes([NSAttributedString.Key.font:
        UIFont.textStyle5], for: .normal)
    } 
}

我使用自定义 UIFont。提前致谢。

最佳答案

你也需要为高亮状态设置相同的字体:

saveBarButton.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.textStyle5], for: .highlighted) 

关于ios - 快速点击条形按钮项目时 UIFont 发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55131534/

相关文章:

ios - "WatchKit Simulator Actions"不适用于实际的 Apple Watch 设备

iphone - 在 iOS 中处理登录和保留 token

flash - 我的 Flash 调试器的地址是什么?

ios - 如何使用 Cocoapods 制作基于两个静态库的动态框架(Swift)

ios - 使用 Swiftui 我们如何创建用户表单

ios - 关闭模态视图 Controller 后如何正确对齐 rightBarButtonItem?

ios - ListView 的 SwiftUI .onDelete 导致应用程序崩溃

swift - 委托(delegate)必须响应 locationManager :didUpdateLocations swift eroor

ios - Swift - UIBarButtonItem.customView - 重置为原始状态

iphone - 允许 UIBarButtonItem 触摸 UINavigationBar 的顶部和底部