6

如何将readonly文本放入UITextField. 例如,iPod touch“其他网络”设置中的“名称”和“安全”字段分别包含“名称”和“安全”这两个词,右侧有一个可编辑区域。 UITextField有一个“占位符”属性,但一旦我输入它就会消失。

4

3 回答 3

6

简单地把这一行放在哪里txtname是对象UITextField

txtName.userInteractionEnabled = NO;
于 2010-07-23T11:50:35.783 回答
2

您在这些字段中看到的不是 UITextField 有标签,而是 UITableViewCell 上有两个控件 - 一个标签和一个没有边框的文本字段。

于 2009-10-08T08:16:39.047 回答
0

在你想要的 UITextField 框架内放置一个 UILabel,然后将 UITextFields“leftView”属性设置为 UILabel。确保将 UITextFields“leftViewMode”属性设置为 UITextFieldViewModeAlways

代码应该看起来像这样..

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 20, 200, 44)];
textField.backgroundColor = [UIColor whiteColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, textField.frame.size.height)];
label.font = [UIFont boldSystemFontOfSize:14.0f];
label.text = @"Name:";
textField.leftView = label;
textField.leftViewMode = UITextFieldViewModeAlways;
[self.view addSubview:textField];
于 2014-08-07T18:37:50.450 回答