簡體   English   中英

如何使故事板中的 UILabel 和 UIButton 大寫

[英]How to make UILabel and UIButton uppercased from storyboard

我在 Storyboard 中找不到通過標志將標簽或按鈕文本大寫的方法,請查看我的 Storyboard 屏幕截圖,其中我向您展示了沒有此類標志的 Attribute Inspector:

在此處輸入圖像描述

目前還沒有為此做好准備,但您可以向Interface Builder添加一個屬性:

只需將其添加到文件中,例如將其命名為XIB+Extension.swift

public protocol UIXIBStyle {
    var uppercased: Bool { get set }
}

extension UILabel: UIXIBStyle {
    @IBInspectable public var uppercased: Bool {
        get { return false }
        set(key) {
            if key {
                text = text?.uppercased()
            }
        }
    }
}

extension UIButton: UIXIBStyle {

    @IBInspectable public var uppercased: Bool {
        get { return false }
        set(key) {
            if key {
                setTitle(currentTitle?.uppercased(), for: .normal)
            }
        }
    }
}

您將能夠在任何UILabelUIButtonAttribute Inspector下看到一個名為 Uppercased 的新屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM