UITextFiedl 左侧设置小图标 leftview

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

实现如下需求

在输入框左侧有一个小图标提示(比如账号左侧一个人的提示,密码左侧有一个锁的提示)


直接上代码


    userName=[[UITextField alloc]initWithFrame:CGRectMake(10, SCREEN_HEIGHT*0.3, SCREEN_WIDTH-20, 36)];  
    userName.placeholder=@"登陆账号";  
    userName.borderStyle=UITextBorderStyleRoundedRect;  
    userName.clearButtonMode=UITextFieldViewModeWhileEditing;  
    UIImageView *imageViewUserName=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];  
    imageViewUserName.image=[UIImage imageNamed:@"userinfo.png"];  
    userName.leftView=imageViewUserName;  
    userName.leftViewMode=UITextFieldViewModeAlways; //此处用来设置leftview现实时机