加入UITextViewDelegate
overridefuncviewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
//设置UITextView
contentTextView.delegate=self
}
当输入框被改变时
functextViewDidChange(_textView:UITextView) {
lettextStrNum = textView.textasNSString
letViewWidth =Int(contentTextView.frame.width/20)
letlineNum =Int(textStrNum.length/ ViewWidth) +1
iftextStrNum.length>0{
contentTextViewplaceholder.isHidden=true
}else{
contentTextViewplaceholder.isHidden=false
}
if( lineNum <=3){
contentTextViewHeight.constant=105
}else{
contentTextViewHeight.constant=CGFloat(32.5*Double(lineNum))
}
}
网友评论