- 设置占位符;
- 使用masonry时无需手动设置height高度;
- 需设置textView的scrollEnabled属性为NO。
注意:设置占位符(占位符的字体大小要和textView的保持一致)
UILabel *placeholdLabel = [UILabel new];
placeholdLabel.text = @"输入地点名称";
placeholdLabel.font = [UIFont systemFontOfSize:14];
placeholdLabel.textColor = ColorHex(0x999999);
placeholdLabel.preferredMaxLayoutWidth = (x_width - 96 - 44);
placeholdLabel.numberOfLines = 0;
_inputView = [UITextView new];
_inputView.delegate = self;
_inputView.font = [UIFont systemFontOfSize:14];
_inputView.textColor = ColorFromHex(0x333333);
_inputView.scrollEnabled = NO;
[_inputView addSubview:placeholdLabel];
[_inputView setValue:placeholdLabel forKey:@"_placeholderLabel"];
[self.contentView addSubview:self.inputView];
网友评论