美文网首页
Swift3.1 UITextView

Swift3.1 UITextView

作者: 文瑶906 | 来源:发表于2017-03-27 11:20 被阅读0次

    一、正常写的代码

    textFiled.font = UIFont.systemFont(ofSize: 14)
            textFiled.textAlignment = .left
            textFiled.layer.cornerRadius = 6
            textFiled.returnKeyType = UIReturnKeyType.done
            textFiled.isScrollEnabled = true
            textFiled.textColor = UIColor(red: 174, green: 183, blue: 186, alpha: 1)
            textFiled.delegate = self
            textFiled.backgroundColor = UIColor.white
    
    textFiled.snp.makeConstraints { (make) in
                make.left.equalTo(icon.snp.left)
                make.right.equalTo(screen_Witch).offset(-12)
                make.height.equalTo(96)
                make.top.equalTo(title.snp.bottom).offset(12)
            }
    
    

    二、添加默认文字

    // textField里面的默认文字
            textLable.frame = CGRect(x: 10, y: 10, width: 200, height: 20)
            textLable.isEnabled = false
            textLable.text = "输入任务描述"
            textLable.font = UIFont.systemFont(ofSize: 14)
            textLable.textColor = UIColor(red: 174, green: 183, blue: 186, alpha: 1)
            textFiled.addSubview(textLable)
    
    extension LJDescriptionCell:UITextViewDelegate{
        /// 设置文本框当输入的时候,不显示默认文字,当文本内容长度为0的时候,显示默认长度
        func textViewDidChange(_ textView: UITextView) {
            
            let strLenght = NSString(string: textFiled.text)
            
            if strLenght.length == 0{
                textLable.isHidden = false
            }
            else{
                textLable.isHidden = true
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:Swift3.1 UITextView

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