PTPPlaceholderTextView
这是一个简单的 TextView 子类实现,用于在 UITextView 中支持 占位符
文本渲染。这个 PTPPlaceholderTextView
包含 IBDesignable,IBInspectable 以及 UIAppearance 支持。
需求
- iOS 8+
- Swift 3.0+
这个需求是由于 Swift 运行时在 iOS 8 或更高版本可用。如果您想使用此 PTPPlaceholderTextView
,请随时与我联系。我还有 Objective-C 实现。
安装
手动安装
此项目包含内置的 PTPPlaceholderTextView 框架
目标。您可以拖动 PTPPlaceholderTextView.xcproj
文件到您的项目中,添加 PTPPlaceholderTextView 框架
目标作为目标依赖,并链接/嵌入该框架。这就完成了!
import PTPPlaceholderTextView
或者,您也可以直接将 PTPPlaceholderTextView.swift
文件添加到您的项目中。
CocoaPod
请在您的 Podfile 中添加以下内容
pod 'PTPPlaceholderTextView'
use_frameworks!
Swift 2.2
通过检出标签 0.6.1
,您可以在 Swift 2.2 中使用 PTPPlaceholderTextView
Swift 3.0
通过检出标签 0.7.0
,您可以在 Swift 2.2 中使用 PTPPlaceholderTextView
Swift 4.0
通过检出标签 0.7.1
,您可以在 Swift 4.0 中使用 PTPPlaceholderTextView
Swift 4.2
通过检出标签 0.7.2
,您可以在 Swift 4.0 中使用 PTPPlaceholderTextView
使用方法
您可以通过 placeholder
属性设置占位文本
textview.placeholder = "Placeholder titile"
通过 placeholderColor
属性设置占位文本颜色
textview.placeholderColor = UIColor.redColor()
您还可以使用 UIAppearance
代理来设置默认占位文本颜色
PTPPlaceholderTextView.appearance().placeholderColor = UIColor.redColor()
或者
PTPPlaceholderTextView.appearanceWhenContainedInInstancesOfClasses([ViewController.self]).placeholderColor = UIColor.redColor()
因为 PTPPlaceholderTextView
支持使用 IBDesignable
和 IBInspectable
。因此,PTPPlaceholderTextView
对象在您的 storyboard
中也可以渲染其预览视图
示例应用
PTPPlaceholderTextView
项目包含一个示例应用目标。您可以通过运行此示例应用目标直接查看 PTPPlaceholderTextView
的使用。示例应用包含 Main.storyboard
,同时也展示了 PTPPlaceholderTextView
的 IBDesignable
功能。
联系方式
Pitiphong Phongpattranont
- [@pitiphong_p 在 Twitter] (https://twitter.com/pitiphong_p)
授权协议
PTPPlaceholderTextView
在 MIT 许可证下发布。
版权所有 © 2015-至今 Pitiphong Phongpattranont。