【问题标题】:Swift: Bolding UIButtonSwift:粗体 UIButton
【发布时间】:2016-09-09 23:49:43
【问题描述】:

是否可以在 UIButton 中加粗字体?使用标签,它非常简单,例如:

label.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0)

但这不适用于按钮。

【问题讨论】:

    标签: swift uibutton label uifont


    【解决方案1】:

    对于UIButton,我尝试了这个并且有效:

    斯威夫特 2

    testButton.titleLabel?.font = UIFont.boldSystemFontOfSize(18)
    

    Swift 3 和 4

    testButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 18)
    

    (感谢ConfusionTowers

    【讨论】:

    • 现在,testButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 18) 从 Swift 4 开始(也可能是 Swift 3)。
    • @ciccioska 这不适用于 iOS 15 按钮,即使我尝试将按钮自定义和样式设为默认值。你能指导我如何在 iOS 15 和 Xcode 13.2.1 中做到这一点吗?
    【解决方案2】:

    Swift 4+

    button.titleLabel?.font = UIFont.systemFont(ofSize: 22.0, weight: .bold)
    

    【讨论】:

      【解决方案3】:

      1) 点击要加粗文本的按钮,然后找到Attributes Inspector

      2) 按“字体”后。它会弹出如下图所示的内容。

      3) 按样式并选择“粗体”。

      4) 点击Done就完成了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-09-07
        • 2021-06-02
        • 1970-01-01
        • 2020-09-16
        • 2011-08-21
        • 2017-01-20
        • 2012-02-23
        相关资源
        最近更新 更多