【发布时间】:2009-10-08 08:12:35
【问题描述】:
如何将readonly 文本放入UITextField。例如,iPod touch“其他网络”设置中的“名称”和“安全”字段分别包含“名称”和“安全”这两个词,右侧有一个可编辑区域。 UITextField 有一个“占位符”属性,但我一输入它就消失了。
【问题讨论】:
标签: ios objective-c uitextfield
如何将readonly 文本放入UITextField。例如,iPod touch“其他网络”设置中的“名称”和“安全”字段分别包含“名称”和“安全”这两个词,右侧有一个可编辑区域。 UITextField 有一个“占位符”属性,但我一输入它就消失了。
【问题讨论】:
标签: ios objective-c uitextfield
只需将这一行放在txtname 是UITextField 的对象处:
txtName.userInteractionEnabled = NO;
【讨论】:
您在这些字段中看到的不是 UITextField 有标签,而是 UITableViewCell 上有两个控件 - 一个标签和一个没有边框的文本字段。
【讨论】:
在你想要的 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];
【讨论】: