JMTextView 1.0.0

JMTextView 1.0.0

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最新发布2017年2月
SwiftSwift 版本3.0
SPM支持 SPM

Jackie Meggesto 维护。



  • 作者
  • jmeggesto

JMTextView

一个可插入的 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;

placeholderattributedPlaceholder 属性设计为保持同步。如果您设置了一个 attributedPlaceholder,然后设置 placeholder 为其他内容,则设置的文本会复制到 attributedPlaceholder 中,同时尽量保留原始文本属性。
此外,当使用 attributedPlaceholder 设置器时,placeholder 将设置为 attributedPlaceholder.string

包含一个简单的演示和几个单元测试。

动画

占位符是可动画的。只需配置 double 属性 fadeTime 为所需动画秒数。

用户定义的运行时属性

如果您更喜欢使用 Interface Builder 来配置您的 UI,则可以使用 UDRA 来设置 placeholderplaceholderTextColor 的值。

贡献力量

  1. 复制此仓库
  2. 创建您的功能分支(git checkout -b my-new-feature
  3. 提交您的更改(git commit -am '添加了一些功能'
  4. 将该分支推送到远程(git push origin my-new-feature
  5. 创建新的 Pull Request

许可证

MIT 许可证 下发布。