Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Table-style TextField for Login Screen?

I wanna make a login screen like the one from Facebook's app. The part I wanna replicate is the two text fields that when stacked look like a table group. I can't figure out how they did it though.

Who knows the trick?

I can't post a picture because I am new to stackoverflow. It's an effect that they seem like one rounded oval but with 2 text fields inside. One for username, one for password.

like image 965
Will Larche Avatar asked Oct 13 '11 03:10

Will Larche


1 Answers

you can use the below code.

//in .h file

UITextField *loginId; 
UITextField *password ;

//in .m file

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return 2;
    }
    - (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {

        UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"Cell"];
        if( cell == nil)
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] autorelease];   

        if (indexPath.row == 0) {
            loginId = [[UITextField alloc] initWithFrame:CGRectMake(5, 0, 280, 21)];
            loginId .placeholder = @"loginid";
            loginId .autocorrectionType = UITextAutocorrectionTypeNo;
            [loginId setClearButtonMode:UITextFieldViewModeWhileEditing];
            cell.accessoryView = loginId ;
        }
        if (indexPath.row == 1) {
            password = [[UITextField alloc] initWithFrame:CGRectMake(5, 0, 280, 21)];
            password.placeholder = @"Password";
            password.secureTextEntry = YES;
            password.autocorrectionType = UITextAutocorrectionTypeNo;
            [password setClearButtonMode:UITextFieldViewModeWhileEditing];
            cell.accessoryView = password;
        }
        loginId.delegate = self;
        password.delegate = self;


        [tableView1 addSubview:loginId];
        [tableView1 addSubview:password];
        [loginId release];
        [password release];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;  
    }
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

        return 1;
    }
like image 150
User97693321 Avatar answered Oct 07 '22 12:10

User97693321