UITextFiedl 左侧设置小图标 leftview

实现如下需求

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



直接上代码


    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现实时机



苹果开发群 :414319235  欢迎加入  欢迎讨论问题

你可能感兴趣的:(UITextField,小图标,leftview)