Swift3.1 UITextView

一、正常写的代码

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
        }
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,990评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,838评论 19 139
  • 杨yang_9682阅读 1,306评论 0 0
  • 一个少年的矫情总是很难做到尽善尽美。 少年时代我们的感情并不像标有刻度尺的咳嗽糖浆瓶子一样易于掌握流量,我们常常对...
    鲍米花阅读 2,600评论 0 2

友情链接更多精彩内容