测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布最新发布 | 2017年2月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Jackie Meggesto 维护。
一个可插入的 UITextView 替换,提供:占位符。
是 SZTextView 的 Swift 版本
技术上它与其他解决方案的不同之处在于,它尝试像 UITextField 的私有 _placeholderLabel
一样工作,因此您不应该遇到不美观的问题,如跳动的文本视图或大量的自定义绘图代码。
运行 Swift 3.0 或更高版本的 iOS 项目。
您可以选择克隆此仓库并将项目添加到您的 Xcode 工作区,或者使用 CocoaPods
let textView: SZTextView = SZTextView()
textView.placeholder = "Enter lorem ipsum here"
textView.placeholderTextColor = UIColor.lightGray
类似地,您可以使用 attributedPlaceholder
属性来设置一个漂亮的 NSAttributedString
作为占位符。
let placeholder: NSMutableAttributedString = NSMutableAttributedString(string: "your lorem ipsum here")
placeholder.addAttribute(NSForegroundColorAttributeName, value: UIColor.red, range: NSMakeRange(0, 2))
placeholder.addAttribute(NSForegroundColorAttributeName, value: UIColor.green, range: NSMakeRange(2, 4))
placeholder.addAttribute(NSForegroundColorAttributeName, value: UIColor.blue, range: NSMakeRange(6, 4))
textView.attributedPlaceholder = placeholder;
placeholder
和 attributedPlaceholder
属性设计为保持同步。如果您设置了一个 attributedPlaceholder
,然后设置 placeholder
为其他内容,则设置的文本会复制到 attributedPlaceholder
中,同时尽量保留原始文本属性。
此外,当使用 attributedPlaceholder
设置器时,placeholder
将设置为 attributedPlaceholder.string
。
包含一个简单的演示和几个单元测试。
占位符是可动画的。只需配置 double
属性 fadeTime
为所需动画秒数。
如果您更喜欢使用 Interface Builder 来配置您的 UI,则可以使用 UDRA 来设置 placeholder
和 placeholderTextColor
的值。
git checkout -b my-new-feature
)git commit -am '添加了一些功能'
)git push origin my-new-feature
)在 MIT 许可证 下发布。