UITextField设置正文缩进

    // 设置文字竖直居中
        loginTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

        // 添加图标

// 设置iconV作为textfield.leftview使输入位置后置缩进
        UIImage *icon = [UIImage imageWithName:iconImageName];
// 在iconV上面添加iconIV 使图片可设置尺寸置中美观
        UIView *iconV = [[UIView alloc] init];
        UIImageView *iconIV = [[UIImageView alloc] initWithImage:icon];

        // 使文字在icon之前30px输入
        iconV.width = 59;
        iconV.height = 53.5;
        iconV.backgroundColor = [UIColor clearColor];
        iconIV.frame = CGRectMake(9, 15, 38, 30);


        [iconV addSubview:iconIV];
        loginTextField.leftView = iconV;

        // 设置icon不拉伸
        iconV.contentMode = UIViewContentModeScaleAspectFit;
        iconIV.contentMode = UIViewContentModeScaleAspectFit;

        // leftView的显示由leftViewMode来确定
        loginTextField.leftViewMode = UITextFieldViewModeAlways;

你可能感兴趣的:(UITextField设置正文缩进)