iOS---textfield设置为只有下划线,并且左边有图片

来源:互联网 发布:python做网站 编辑:程序博客网 时间:2024/04/28 21:03



    self.phoneField.font = [UIFont systemFontOfSize:15];

    self.phoneField.placeholder =@"请输入";   

    

    // 通过init来创建初始化绝大部分控件,控件都是没有尺寸

    UIImageView *icon = [[UIImageViewalloc]init];

  

    icon.image = [UIImageimageNamed:@"phone"];

    icon.width =30;

    icon.height =30;


    icon.contentMode =UIViewContentModeCenter;

    self.phoneField.leftView =icon;

    self.phoneField.leftViewMode = UITextFieldViewModeAlways;



  /** ---------------------------------------------------------------------------*/



 //设置无边框(可以直接在sb中设置)

    // self.phoneField.borderStyle = UITextBorderStyleNone;

    

    //手机号

    self.phoneField.font = [UIFont systemFontOfSize:15];

    self.phoneField.placeholder =@"请输入手机号";

    UIView *line=[[UIViewalloc]initWithFrame:CGRectMake(0,self.phoneField.height-2,self.phoneField.width,1)];

    line.backgroundColor=[UIColorlightGrayColor];

    [self.phoneFieldaddSubview:line];

    

    // 通过init来创建初始化绝大部分控件,控件都是没有尺寸

    UIImageView *searchIcon = [[UIImageViewalloc] init];

    searchIcon.image = [UIImageimageNamed:@"phone"];

    searchIcon.width = 30;

    searchIcon.height = 30;

    searchIcon.contentMode =UIViewContentModeCenter;

    self.phoneField.leftView = searchIcon;

    self.phoneField.leftViewMode = UITextFieldViewModeAlways;

    

   

    

    //密码

    self.pwdField.font = [UIFont systemFontOfSize:15];

    self.pwdField.placeholder =@"请输入密码";

    UIView *line2=[[UIViewalloc]initWithFrame:CGRectMake(0,self.pwdField.height-1,self.pwdField.width,1)];

    line2.backgroundColor=[UIColorlightGrayColor];

    [self.pwdFieldaddSubview:line2];

    

    // 通过init来创建初始化绝大部分控件,控件都是没有尺寸

    UIImageView *searchIcon2 = [[UIImageViewalloc] init];

    searchIcon2.image = [UIImageimageNamed:@"pwd"];

    searchIcon2.width = 30;

    searchIcon2.height = 30;

    searchIcon2.contentMode =UIViewContentModeCenter;

    self.pwdField.leftView = searchIcon2;

    self.pwdField.leftViewMode = UITextFieldViewModeAlways;




0 0
原创粉丝点击