Providing editable and non-editable fields on iPhone

I would like to provide information to the user of my application in an uneditable way, but allow editing after clicking the button (edit button). Is there a way to easily create this transition from uneditable to editable?

I reviewed the use of UILabel for non-editable fields and programmatically deleting them and showing UITextField . However, it seems that this would attach great importance to formatting the code, which I would prefer not to do (to preserve the benefits of IB).

I also considered having both UILabel and UITextField in the same place at my tip and trying to hide the one I don't want. It seems pretty hacky though.

Maybe I just feel better with two separate views?

Any comments on the above methods or the best ways to execute them would be greatly appreciated.

+7
iphone uilabel uitextfield
source share
2 answers

if you set the enabled UITextField property to NO and change borderStyle to UITextBorderStyleNone, your text box looks almost like UILabel. Perhaps you want to switch these two values. Something like that:
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]; } } } } 
+7
source share

As fluchtpunkt said, you can do it too. Otherwise, you can provide one label and one text box with the same frame size. And on editable truth, you can hide the shortcut that displays the text box. And for editing false, you can show the shortcut by hiding the text box.

0
source share

All Articles