Display and hide Textfield programmatically for iPhone/Cocoa Touch
I'm trying to create a custom editor for my UIViewController. It was suggested that I hide the textfields until the 开发者_Go百科user presses the Edit key. How do you do this programmatically?
In other words when the user hits 'Edit' I would like the label to disappear and the Textfield to appear.
Thanks,
You can make use of the hidden
property for quickly turning something visible or invisible.
self.widget1.hidden = YES;
self.widget2.hidden = NO;
Another option is to set alpha to 0 to hide and 1 to show. This is beneficial if you want to have an animation fade the widgets in and out for a smooth transition.
[UIView beginAnimations:nil context:NULL];
self.widget1.alpha = 0;
self.widget2.alpha = 1;
[UIView commitAnimations];
You just need to use the hidden
property.
label.hidden = YES;
textField.hidden = NO;
精彩评论