iOS 在cell上面设置登陆账号密码

如何在cell上面设置登陆账号密码,就是在里面设置一个图片和输入框,代码如下:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

//    //去掉分割线

//    [tv setSeparatorStyle:UITableViewCellSeparatorStyleNone];

    if ([[[UIDevicecurrentDevice] systemVersion]floatValue] >= 7.0) {

        [tv setSeparatorInset:(UIEdgeInsetsMake(0, 0, 0, 0))];

    }

    static NSString *CellWithIdentifier =@"loginCell";

    UITableViewCell *cell = [tvdequeueReusableCellWithIdentifier:CellWithIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellWithIdentifier];

    }

     cell.selectionStyle =UITableViewCellSelectionStyleNone;

    if (indexPath.section == 1) { // 设置第一组的<span>登录</span>框内容

        switch ([indexPath row]) {

            case 0:

//                [cell.imageView setImage:[UIImage imageNamed:@"user"]];

//                cell.textLabel.text = @"账号"; //设置label的文字

            {

                UIImageView *userImageView = [[UIImageViewalloc]initWithFrame:CGRectMakeAuto(30, 15, 20, 20)];

                userImageView.image = [UIImageimageNamed:@"user" ];

                userImageView.contentModeUIViewContentModeScaleAspectFill;

                  // 设置不能点击

                self.nameField = [[UITextFieldalloc] initWithFrame:CGRectMakeAuto(70, 6, 220, 44)];

               

//                [self.nameField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型

                self.nameField.autocapitalizationType =UITextAutocapitalizationTypeNone;

                self.nameField.clearButtonMode =UITextFieldViewModeUnlessEditing;

                self.nameField.placeholder =@"Username";

                [self.nameFieldsetValue:[UIColorlightTextColor] forKeyPath:@"_placeholderLabel.textColor"];

                self.nameField.textColor = [UIColorwhiteColor];

//                self.nameField.clearButtonMode = YES; // 设置清除输入文本

                self.nameField.returnKeyType =UIReturnKeyNext;

                [self.nameFieldaddTarget:selfaction:@selector(nameTextField_DidEndOnExit:)forControlEvents:UIControlEventEditingDidEndOnExit];

                [cell.contentViewaddSubview:self.nameField];

                [cell.contentView addSubview:userImageView];

            }

                break;

            default:

            {

                UIImageView *passImageView = [[UIImageViewalloc]initWithFrame:CGRectMakeAuto(30, 15, 20, 20)];

                passImageView.image = [UIImageimageNamed:@"pass" ];

                passImageView.contentModeUIViewContentModeScaleAspectFill;

//                cell.backgroundView  = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"y.png"]];

//                cell.textLabel.text = @"密码";

                self.pwdField = [[UITextFieldalloc] initWithFrame:CGRectMakeAuto(70, 6, 220, 44)];

                self.pwdField.clearButtonMode =UITextFieldViewModeWhileEditing;

                self.pwdField.autocapitalizationType =UITextAutocapitalizationTypeNone;

//                [self.pwdField setBorderStyle:UITextBorderStyleRoundedRect];

                  //外框类型

                  self.pwdField.secureTextEntry =YES;

                self.pwdField.placeholder =@"Password";

                [self.pwdFieldsetValue:[UIColorlightTextColor] forKeyPath:@"_placeholderLabel.textColor"];

//                self.pwdField.clearButtonMode = YES;

                self.pwdField.returnKeyType =UIReturnKeyGo;

                [self.pwdFieldaddTarget:selfaction:@selector(passTextField_DidEndOnExit:)forControlEvents:UIControlEventEditingDidEndOnExit];

                self.pwdField.textColor = [UIColorwhiteColor];

                [cell.contentViewaddSubview:self.pwdField];

                [cell.contentView addSubview:passImageView];

            }

                break;

        }

        NSUserDefaults *userDefault = [NSUserDefaultsstandardUserDefaults];

        NSString *name = [userDefault objectForKey:@"name"];

        if (name) {

            self.nameField.text = name;

        }

    }

    else {

//

    }

    cell.backgroundColor = [UIColorclearColor];

    return cell;

}


效果如下图:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值