【问题标题】:Adding placeholder to textfield on table view cell将占位符添加到表格视图单元格上的文本字段
【发布时间】:2015-12-29 19:58:32
【问题描述】:

我在表格视图单元格上创建了​​一个文本字段。但我希望能够添加一个占位符。

【问题讨论】:

标签: swift uitableview uitextfield


【解决方案1】:

您可以使用检查面板中的占位符字段,如下所示。如果您想以编程方式执行此操作,可以使用与此类似的东西

 //create the attribute dictionary
let placeholderAttr = [
  NSForegroundColorAttributeName: UIColor.lightGrayColor(),
  NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 22.0)!,
]

//apply the attributes to the placeholder
yourTextField.attributedPlaceholder = NSAttributedString(string: "This is your placeholder text", attributes: placeholderAttr)
yourTextField.textAlignment = NSTextAlignment.Left

【讨论】:

    猜你喜欢
    • 2017-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 2018-11-21
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多