如何在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.contentMode = UIViewContentModeScaleAspectFill;
// 设置不能点击
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.contentMode = UIViewContentModeScaleAspectFill;
// 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;
}