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

Ale*_*eks 3 xcode storyboard ios swift

我在 Storyboard 中找不到通过标志使我的标签或按钮文本大写的方法,请检查我的 Storyboard 屏幕截图,我向您展示了没有此类标志的属性检查器:

在此处输入图片说明

den*_*lor 5

目前还没有准备好,但你可以添加一个属性到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)
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

您将能够在Attribute Inspectorfor anyUILabel或下看到一个名为 Uppercased 的新属性UIButton。