iOS:登录屏幕的表格式TextField?

Wil*_*che 12 iphone xcode objective-c login-control ios

我想创建一个像Facebook的应用程序那样的登录屏幕.我要复制的部分是两个文本字段,堆叠时看起来像一个表组.我无法弄清楚他们是如何做到的.

谁知道诀窍?

我无法发布图片,因为我是stackoverflow的新手.这是一种效果,它们看起来像一个圆形椭圆形但内部有2个文本字段.一个用于用户名,一个用于密码.

Use*_*321 11

你可以使用下面的代码.

//在.h文件中

UITextField *loginId; 
UITextField *password ;
Run Code Online (Sandbox Code Playgroud)

//在.m文件中

- (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;
    }
Run Code Online (Sandbox Code Playgroud)


UPT*_*UPT 9

从这里获取代码:https://github.com/c99koder/lastfm-iphone

如果您下载代码并查看FirstRunView.xib,您将看到所需的相同实现.

  • 对于任何看过lastfm代码的人来说,它只是一个头,它使用图像来实现分组的TableView效果. (5认同)