iOS TextField和TextView的占位字符自定义

TextField

[textFeild setValue:[UIColor WhiteColor] forKeyPath:@"placeholderLabel.textColor"];//设置占位字符颜色
[textFeild setValue:[UIFont systemFontOfSize:32] forKeyPath:@"placeholderLabel.font"];//设置占位字符大小

TextView(自动识别是否有内容显示和隐藏占位字符)

- (void)setupTextView
{
    UILabel *placeHolderLabel = [[UILabel alloc] init];
    placeHolderLabel.text = @"占位字符串内容";
    placeHolderLabel.numberOfLines = 0;
    placeHolderLabel.textColor = UIColor;
    [placeHolderLabel sizeToFit];
    [_addressTextView addSubview:placeHolderLabel];
    _addressTextView.font = [UIFont systemFontOfSize:14.f];
    placeHolderLabel.font = [UIFont systemFontOfSize:14.f];
    
    [_addressTextView setValue:placeHolderLabel forKey:@"placeholderLabel"];
}

你可能感兴趣的:(iOS TextField和TextView的占位字符自定义)