【问题标题】:How to make a custom UITextField Placeholder in Swift 3.0如何在 Swift 3.0 中制作自定义 UITextField 占位符
【发布时间】:2017-10-01 18:16:09
【问题描述】:

我正在构建一个必须获取用户地址和一些信息的应用程序。我有一个带有三个 UITextField 的 UIViewController,我想像这张图片一样显示每个 TextField 的占位符。

UIViewController 的样机设计

我该怎么做?

【问题讨论】:

标签: ios swift textfield placeholder


【解决方案1】:

UITextField 具有内置的占位符功能。只需设置文本字段的placeholder 属性:

textField.placeholder = "Casa 9 manzana E"

您可以根据需要设置文本字段的样式。查看UITextField 文档了解更多详细信息:https://developer.apple.com/reference/uikit/uitextfield

【讨论】:

    【解决方案2】:

    对于多行样式占位符,请考虑使用attributedPlaceholderNSAttributedString 允许以不同方式修改/样式化字符串的各个部分。

    【讨论】:

      【解决方案3】:

      你需要试试这个

      Txtpwd.attributedPlaceholder = NSAttributedString(string: "Your Text",attributes: [NSForegroundColorAttributeName=UIColor.darkGray])

      TxTPwd 在昔日 TextField 出口中的位置

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-11-10
        • 2019-01-13
        • 2021-01-12
        • 1970-01-01
        • 2019-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多