//    UIView *paddingView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 50)];
//    paddingView1.backgroundColor = [UIColor lightGrayColor];
//    self.phoneTextField .leftView = paddingView1;
//    self.phoneTextField.leftViewMode = UITextFieldViewModeAlways;
//    [self.view addSubview:paddingView1];
//    
//    self.phoneTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, 0, self.view.frame.size.width,textFieldH )];
//    self.phoneTextField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"手机" attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
//    self.phoneTextField.delegate = self;
//    self.phoneTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
//    self.phoneTextField.returnKeyType = UIReturnKeyDone;
//    [paddingView1 addSubview:self.phoneTextField];

这是第一种办法,就是添加leftview

第二种就是自定义UItextField

#import <UIKit/UIKit.h>

@interface textField : UITextField

//控制 placeHolder 的位置,左右缩 10
- (CGRect)textRectForBounds:(CGRect)bounds;

// 控制文本的位置,左右缩 10
- (CGRect)editingRectForBounds:(CGRect)bounds;
@end
textField.m

#import "textField.h"

@implementation textField

- (CGRect)textRectForBounds:(CGRect)bounds {
    return CGRectInset( bounds , 10*1 , 0 );
}

// 控制文本的位置,左
- (CGRect)editingRectForBounds:(CGRect)bounds {
    return CGRectInset( bounds , 10*1 , 0 );
}
@end

相关文章:

  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2022-02-13
  • 2021-09-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案