美文网首页
[iOS功能]- iOS改变占位符颜色

[iOS功能]- iOS改变占位符颜色

作者: AlwaysLuckyMa | 来源:发表于2020-02-26 15:36 被阅读0次
    self.passTF.attributedPlaceholder = [self changePlaceholderWithTextField:self.passTF withString:@"请输入密码"];
    
    - (NSMutableAttributedString *)changePlaceholderWithTextField:(UITextField *)textField withString:(NSString *)string{
        //设置光标颜色
        textField.tintColor = [UIColor whiteColor];
        textField.textColor = [UIColor whiteColor];
        //placeholder前面加入空格
        textField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 42/2/1.5, 0)];
        textField.leftViewMode = UITextFieldViewModeAlways;
        NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:string];
        if (SCREEN_WIDTH == 320) {
            [attributeString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:NSMakeRange(0, string.length)];
        }else{
            [attributeString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:NSMakeRange(0, string.length)];
        }
        //设置placeholder字体的颜色
        [attributeString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:152/255.0 green:152/255.0 blue:152/255.0 alpha:1] range:NSMakeRange(0, string.length)];
        
        return attributeString;
    }
    

    相关文章

      网友评论

          本文标题:[iOS功能]- iOS改变占位符颜色

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