如何使故事板中的 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)
}
}
}
}
对于任何 UILabel
或 UIButton
.
,您将能够在 Attribute Inspector
下看到一个名为 Uppercased 的新属性
我在 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)
}
}
}
}
对于任何 UILabel
或 UIButton
.
Attribute Inspector
下看到一个名为 Uppercased 的新属性