美文网首页iOS自我学习库
iOS TextField和TextView的占位字符自定义

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

作者: 野生塔塔酱 | 来源:发表于2017-11-15 15:35 被阅读57次

    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的占位字符自定义

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