【问题标题】:UITextField placeholder text is truncating with "..."UITextField 占位符文本用“...”截断
【发布时间】: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


【解决方案1】:

我认为 "Regular 18.0" 不是有效的字体名称。您可以通过以下方式查找您拥有的字体:



    for familyNames in UIFont.familyNames() {
        for fontNames in UIFont.fontNamesForFamilyName(familyNames) {
            print(fontNames)
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-21
    • 1970-01-01
    • 2013-10-08
    • 1970-01-01
    • 2014-02-17
    • 2012-01-21
    • 2014-09-02
    • 2010-11-23
    相关资源
    最近更新 更多