I would like to present information to the user of my app in a non-editable way but allow editing after a button press (of the edit button). Is there any way of easily creating this transition from non-editable to editable?
I have considered using UILabel
s for the non-editable fields and programatically removing them and showing UITextField
s instead. However, this would seem to put a lot of the formatting into code which I would prefer not to do (to keep the advantages of IB).
I also considered having both UILabel
and UITextField
in the same place in my nib and trying to hide the one I don't want. This seems quite hacky though.
Maybe I would just be best off with two separate views?
Any comments on the above methods or better ways of doing it would be very much appreciated.
if you set the enabled property of a UITextField to NO and change the borderStyle to UITextBorderStyleNone your textfield looks almost like a UILabel.
Maybe you want to toggle those two values.. Something like this:
EDIT: And if you change the font they look exactly like UILabels.
- (IBAction)toggleEdit:(id)sender {
for (id subview in self.view.subviews) {
if ([subview isKindOfClass:[UITextField class]]) {
BOOL isEnabled = ((UITextField*)subview).enabled;
((UITextField*)subview).enabled = !isEnabled;
if (isEnabled) {
// Disable
((UITextField*)subview).borderStyle = UITextBorderStyleNone;
((UITextField*)subview).font = [UIFont systemFontOfSize:17.0];
}
else {
// Enable
((UITextField*)subview).borderStyle = UITextBorderStyleRoundedRect;
((UITextField*)subview).font = [UIFont systemFontOfSize:12.0];
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With