美文网首页
textfield左边加图片和空几格

textfield左边加图片和空几格

作者: 长风破浪初学者 | 来源:发表于2016-08-08 11:39 被阅读0次

    -(void)setTextFiledLeftImage:(UITextField*)textFiled image:(NSString*)image forWidth:(CGFloat)leftWidth

    {

    CGRect frame = textFiled.frame;

    frame.size.width = leftWidth;

    UIView *leftview = [[UIView alloc] initWithFrame:frame];

    UIImageView *leftImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, (FUll_VIEW_HEIGHT*0.08 -23)/2, 20, 23)];

    leftImage.image = [UIImage imageNamed:image];

    [leftview addSubview:leftImage];

    textFiled.leftViewMode = UITextFieldViewModeAlways;

    textFiled.leftView = leftview;

    }

    账户和密码引用

    [self setTextFiledLeftImage:self.UserName image:@"手机@2x.png"    forWidth:50];

    [self setTextFiledLeftImage:self.PassWord image:@"密码@2x.png" forWidth:50];

    单纯的空几个格

    -(void)setTextFiledLeft:(UITextField*)textFiled forWidth:(CGFloat)leftWidth

    {

    CGRect frame = textFiled.frame;

    frame.size.width = leftWidth;

    UIView *leftview = [[UIView alloc] initWithFrame:frame];

    textFiled.leftViewMode = UITextFieldViewModeAlways;

    textFiled.leftView = leftview;

    }

    相关文章

      网友评论

          本文标题:textfield左边加图片和空几格

          本文链接:https://www.haomeiwen.com/subject/yscrsttx.html