我在情节提要中找不到通过标志将标签或按钮文本变为大写的方法,请查看我的情节提要屏幕截图,其中我向您展示了没有此类标志的属性检查器:
1 回答
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)
}
}
}
}
您将能够在Attribute Inspectorfor anyUILabel或下看到一个名为 Uppercased 的新属性UIButton。

于 2020-01-20T22:54:55.433 回答
