美文网首页
UITextView添加placeholder

UITextView添加placeholder

作者: 静静ZZ | 来源:发表于2017-11-18 17:31 被阅读0次
    //本文采用的代码量比较少的一种写法,测试中未出现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

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