【问题标题】:Red Asterisk directly beside placeholder in input box in ios?ios输入框中占位符旁边的红色星号?
【发布时间】:2017-10-08 18:06:21
【问题描述】:

我想在我使用 uitextfield 的注册表单中除了 ios 中的占位符之外放置一个 red asterix( * )。我知道如何更改占位符颜色,但在我的要求中,我将占位符颜色设置为灰色,后面有 red asterix( * )。如何在 swift 3 中实现这一点?是否可以在情节提要本身中设置它?

【问题讨论】:

  • 您可以在文本字段上设置图像。
  • 那么如何在输入 uitextfield 时隐藏图像?
  • 这可能对你有帮助:stackoverflow.com/a/13695462/3927536
  • 检查 shouldChangeCharactersInRange 委托方法

标签: ios objective-c swift3 storyboard


【解决方案1】:

您可以使用UITextField 的内置attributedPlaceholder 属性。

像这样:

    let passwordAttriburedString = NSMutableAttributedString(string: "Password")
    let asterix = NSAttributedString(string: "*", attributes: [.foregroundColor: UIColor.red])
    passwordAttriburedString.append(asterix)
            
    self.textField.attributedPlaceholder = passwordAttriburedString

【讨论】:

    猜你喜欢
    • 2015-05-31
    • 2018-10-29
    • 2018-06-22
    • 2019-07-03
    • 1970-01-01
    • 2019-03-17
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多