需要给UITextView去添加,像UITextField的placeholder
swift uitextview placeholder
ios – Text View Placeholder Swift – Stack Overflow
MoZhouqi/KMPlaceholderTextView · GitHub
aaron7pm/Swift-UITextView-Placeholder-Example · GitHub
https://github.com/MoZhouqi/KMPlaceholderTextView/archive/master.zip
去试试。
代码:
var descTextView:KMPlaceholderTextView init(curContactItem:ContactItem){ self.descTextView = KMPlaceholderTextView() super.init(nibName: nil, bundle: nil) } //2. description textview self.descTextView.font = UIFont.systemFontOfSize(14) self.descTextView.backgroundColor = UIColor.whiteColor() self.descTextView.placeholder = "输入" + curTypeStr + "简述" self.descTextView.delegate = self self.descTextView.layer.borderWidth = 1 self.descTextView.layer.borderColor = UIColor.grayColor().CGColor self.descTextView.layer.cornerRadius = 4 self.view.addSubview(self.descTextView) |
效果还不错:
点击后,出现键盘后,没有输入内容时,也是有placeholder的:
输入内容后:
[后记]
后来去再次用到这个库
github "MoZhouqi/KMPlaceholderTextView" >= 1.2
转载请注明:在路上 » [已解决]swift给UITextView加placeholder