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

问题描述:

我想从Facebook的应用程序中创建一个登录屏幕。我想复制的部分是两个文本字段,当堆叠看起来像一个表组。我无法弄清楚他们是如何做到的。iOS:用于登录屏幕的表格式TextField?

谁知道这个诀窍?

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

+0

您可能也对这个已经写好的控件感兴趣:http://cocoacontrols.com/platforms/ios/controls/ddalertprompt – Luke

+0

如果你想上传图片,你可以使用下面的链接中显示的控件图片:http://img31.imageshack.us/img31/566/screenshot20111015at317.png – User97693321

你可以使用下面的代码。

//在.h文件中

UITextField *loginId; 
UITextField *password ; 

//在.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; 
    } 
+0

请使用评论选项进行评论。 – JustSid

+0

很好的答案,但有一个问题。有没有办法移动2个分组的单元格的位置,或者他们将不得不停留在屏幕的顶部? – BlueMeanie

只需使用具有圆角的UIVIew作为背景并将两个文本字段添加为子视图即可。

您可以带上UITableView并加上UITextField作为accessoryType为您的目的。

啊!我得到了答案。这只是艺术。这是一个UIImage,它看起来像带有无边界UITextFields的2单元格tableview。为什么我从来不猜这是艺术?

乘坐从这里代码:如果你下载的代码https://github.com/c99koder/lastfm-iphone

,展望FirstRunView.xib将会根据需要看到相同的实现。

+5

只是为了让任何人看看lastfm代码,它使用图像来实现分组的TableView影响。 –