iOS-textfield控制光标开始位置
// 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