由于UITextField的光标位置 是紧贴左边框的, 看起来不美观,如下图
可以通过设置UITextField的leftView 让其右移 如下图:
代码如下:
UITextField *textField = [[UITextField alloc] init];
textField.delegate = self;
textField.backgroundColor = [UIColor whiteColor];
textField.layer.cornerRadius = 5;
textField.layer.masksToBounds = YES;
[self.bgView addSubview:textField];
UILabel * leftView = [[UILabel alloc] initWithFrame:CGRectMake(10,0,7,26)];
leftView.backgroundColor = [UIColor clearColor];
textField.leftView = leftView;
textField.leftViewMode = UITextFieldViewModeAlways;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;