UITextField
*testField = [[
UITextField
alloc
]
initWithFrame
:
CGRectMake
(
20
,
100
,
180
,
30
)];
testField. borderStyle = UITextBorderStyleRoundedRect ;
testField. borderStyle = UITextBorderStyleRoundedRect ;
//开启左边视图出现模式
testField. leftViewMode = UITextFieldViewModeAlways ;
testField. leftViewMode = UITextFieldViewModeAlways ;
UIImageView *imageView = [[ UIImageView alloc ] initWithFrame : CGRectMake ( 0 , 0 , 40 , 30 )];
UIImage *image = [ UIImage imageNamed : @"userName.png" ];
imageView. image = image;
//设置TextField左边视图
testField. leftView = imageView;
[ self . view addSubview :testField];
testField. leftView = imageView;
[ self . view addSubview :testField];