【发布时间】:2016-05-10 14:58:51
【问题描述】:
即使我这样做了,我的占位符文本(我有一个 IB UITextfield)也没有调整大小:
textField.adjustsFontSizeToFitWidth = true
textField.minimumFontSize = 1
我试过用这个:
let attributedplaceholder = NSAttributedString(string: placeholderText,
attributes: [NSFontAttributeName:
UIFont(name: "fontName", size: 10)!])
textField.attributedPlaceholder = attributedplaceholder
但这给出了例外:
exception Storyboard (<UIStoryboard: 0x7fd04359b200>) doesn't
contain a view controller with identifier 'xxx'
fatal error: unexpectedly found nil while unwrapping an Optional value
我也不知道在使用attributedplaceholder 时如何使用adjustFontSize 来适应宽度?
有人可以帮忙吗?
谢谢。
【问题讨论】:
-
格式化后,您的问题不可读。您能否使用此处提供的格式选项,让您的问题对社区更具吸引力?欢迎来到 SO。
-
请注意,在 Swift 中,变量和属性名称的约定是不使用 CamelCase(如
TextField)。请改用textField之类的名称。
标签: swift placeholder truncation