美文网首页
五种方法实现UITextView的Placeholder

五种方法实现UITextView的Placeholder

作者: 悦思 | 来源:发表于2016-05-04 17:50 被阅读117次

项目中有这个需求,查了简书很多种方法实现,自己汇总了五种方法在这里记录下来。
方法1:猥琐法: 把UITextView的text当placeholder使用。但是当文字和placeholder一致时失效。
方法2:画文字法:使用DrawRect把占位文字画上去,使用通知,当有实际内容的时候就不画。
方法3:label法: 使用一个label作为占位文字的载体,当没有内容时显示label,有内容时隐藏label
方法4:高逼格法:分类中使用运行时添加一个textView作为placeholder。代理控制有内容显示没内容隐藏。
方法5:用第三方 占位文字设置 href:RPFloatingPlaceholders
Demo in Github:UITextView的Placeholder

TextView placeholder gif.gif

相关文章

网友评论

      本文标题:五种方法实现UITextView的Placeholder

      本文链接:https://www.haomeiwen.com/subject/dporrttx.html