美文网首页
解决UItextView没有placeholder的问题

解决UItextView没有placeholder的问题

作者: 书韵味 | 来源:发表于2017-11-21 14:21 被阅读6次
{
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 100];
    [textView setBackgroundColor:[UIColor greenColor]];
    [self.view addSubview:textView];

    // _placeholderLabel
    UILabel *placeHolderLabel = [[UILabel alloc] init];
    placeHolderLabel.text = @"请输入内容";
    placeHolderLabel.numberOfLines = 0;
    placeHolderLabel.textColor = [UIColor lightGrayColor];
    [placeHolderLabel sizeToFit];
    [textView addSubview:placeHolderLabel];

    // same font
    textView.font = [UIFont systemFontOfSize:13.f];
    placeHolderLabel.font = [UIFont systemFontOfSize:13.f];

    [textView setValue:placeHolderLabel forKey:@"_placeholderLabel"];
}

通过修改textView原生的API来实现没有placeholder问题

转自:http://www.jianshu.com/p/9edb8be75e0b

相关文章

网友评论

      本文标题:解决UItextView没有placeholder的问题

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