xcode iOS:用于登录屏幕的表格样式文本字段?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7748997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS: Table-style TextField for Login Screen?
提问by Will Larche
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.
我想做一个像 Facebook 应用程序那样的登录屏幕。我想要复制的部分是堆叠时看起来像一个表格组的两个文本字段。我无法弄清楚他们是如何做到的。
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.
我无法发布图片,因为我是 stackoverflow 的新手。这是一种效果,它们看起来像一个圆形的椭圆形,但里面有 2 个文本字段。一个是用户名,一个是密码。
采纳答案by User97693321
you can use the below code.
您可以使用以下代码。
//in .h file
//在.h文件中
UITextField *loginId;
UITextField *password ;
//in .m file
//在.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;
}
回答by UPT
Take the code from here: https://github.com/c99koder/lastfm-iphone
从这里获取代码:https: //github.com/c99koder/lastfm-iphone
if you download the code and look into the FirstRunView.xib you will see the same implementation as desired.
如果您下载代码并查看 FirstRunView.xib,您将看到所需的相同实现。
回答by Will Larche
Ah! I got the answer. It's just art. It's an UIImage that looks like a 2 cell tableview with borderless UITextFields. Why do I never guess it's art?
啊! 我得到了答案。这只是艺术。它是一个 UIImage,看起来像一个带有无边框 UITextField 的 2 单元格 tableview。为什么我从来不认为这是艺术?
回答by Akshay
Just use a UIVIew with rounded corners for the background and add the two text fields as sub views.
只需使用带圆角的 UIVIew 作为背景,并将两个文本字段添加为子视图。
回答by Suraj Mirajkar
You can take a UITableView
and add UITextField
as accessoryType
for your purpose.
您可以将 aUITableView
和 add UITextField
asaccessoryType
用于您的目的。