//懒加载文本输入框 private lazy var textView: UITextView = { let textView = UITextView() textView.font = UIFont.systemFontOfSize(18) textView.textColor = UIColor.darkGrayColor()
//处理键盘,设置键盘的消失模式 textView.keyboardDismissMode = UIScrollViewKeyboardDismissMode.OnDrag //设置弹簧效果 textView.alwaysBounceVertical = true
return textView }() //懒加载占位文本 private lazy var placeHoderLabel: UILabel = UILabel(title: "分享新鲜事...", size: 18, color: UIColor.lightGrayColor()) //设置输入文本框 private func setTextView() { //添加子控件 view.addSubview(textView) textView.backgroundColor = UIColor.randomColor()
//设置约束 textView.snp_makeConstraints { (make) -> Void in make.top.left.right.equalTo(self.view) make.height.equalTo(view.bounds.height / 3) } //添加占位文本 textView.addSubview(placeHoderLabel) //约束 placeHoderLabel.snp_makeConstraints { (make) -> Void in make.top.equalTo(textView.snp_top).offset(8) make.left.equalTo(textView.snp_left).offset(5) } }