Putting readonly header in UITextField

How to place text readonlyinside UITextField. For example, the Name and Security fields in the iPod touch settings for Other Networks contain the words Name and Security, respectively, and an editable area to the right. UITextFieldhas the "placeholder" property, but it disappears as soon as I type.

+5
source share
3 answers

Just put this line where txtnameis the object UITextField:

txtName.userInteractionEnabled = NO;
+5
source

, , , UITextField , , UITableViewCell - .

+2

Place the UILabel inside your UITextField frame where you want, then set the UITextFields leftView property to UILabel. Verify that the UITextFields leftViewMode property is set to UITextFieldViewModeAlways

The code should look something like this.

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];
0
source

All Articles