ios-如何设置UITextField占位字符的颜色和光标颜色

  • 废话不多说,直接上代码
    self.passwordTF.tintColor = [UIColor whiteColor];// 设置光标颜色
    // 创建一个富文本对象
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    // 设置富文本对象的颜色
    attributes[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#FFFFFF"];
    // 设置UITextField的占位文字及占位文字的颜色
    self.passwordTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"密码" attributes:attributes];
    // 设置边框颜色
    self.passwordTF.layer.borderColor= [UIColor colorWithHexString:@"#1380C5"].CGColor;
    self.passwordTF.layer.borderWidth= 1.0f;
    self.passwordTF.layer.cornerRadius = 4;
    self.passwordTF.clipsToBounds = YES;

    // 如何设置文本距离文本框左边有10的间距
    // 设置文本距离左边有10的间距
    self.passwordTF.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 0)];
    //设置显示模式为永远显示(默认不显示)
    self.passwordTF.leftViewMode = UITextFieldViewModeAlways;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容