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"];
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • UITextField : 只能输入一行,不可以滚动,可以设置提醒文字。 UITextView: 能输入多行,可以...
    甜水八角阅读 8,712评论 0 5
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,195评论 4 61
  • 有关因材施教调查问卷: 一,请写出孩子的两个好朋友的名字并且简要描述孩子对他们的评价。 豆豆哥和满满哥 仔儿到现在...
    仔儿娘阅读 1,176评论 0 0
  • 研究生宿舍的右边是一所小学,后面有一片池塘,池水不多,满是青青的芦苇。如果夜晚从池塘边走过,准会被藏在其中的青蛙吓...
    当年雪阅读 793评论 2 0