UITableVIewCell + UITextView简单实现

2021-09-16  本文已影响0人  歩羡仙
  1. 设置占位符;
  2. 使用masonry时无需手动设置height高度;
  3. 需设置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];

上一篇下一篇

猜你喜欢

热点阅读