//本文采用的代码量比较少的一种写法,测试中未出现bug
#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()
@property (nonatomic, strong) UITextView *textView;
@end
@implementation ViewController
- (void)viewDidLoad {
[self.view addSubview:self.textView];
[self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(100);
make.height.equalTo(@48);
make.right.equalTo(self.inputView).offset(-20);
make.left.equalTo(self.inputView).offset(20);
}];
}
-(UITextView *)textView{
if (!_textView) {
_textView = [[UITextView alloc] init];
_textView.font = [UIFont systemFontOfSize:14];
_textView.textColor = MIN_BLACKTITLE_COLOR;
UILabel *placeHolderLabel = [[UILabel alloc] init];
placeHolderLabel.text = @"请输入您的评论";
placeHolderLabel.textColor = [UIColor lightGrayColor];
placeHolderLabel.font = [UIFont systemFontOfSize:14];
[placeHolderLabel sizeToFit];
[_textView addSubview:placeHolderLabel];
[_textView setValue:placeHolderLabel forKey:@"_placeholderLabel"];
}
return _textView;
}
@end
UITextView添加placeholder
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 实现方法:通过监听UITextView的文本变化,重绘UITextView将placeholder绘制出来。 支持...
- 在实际项目开发中经常有需要在UITextView中添加提示用户输入的一些文字,类似UITextField的Plac...