Reputation: 15639
I made an xib
and showed it inside a view by following code.
NSArray *xibContents =
[[NSBundle mainBundle] loadNibNamed:@"PickupAddressView"
owner:self
options:nil];
UIView *view = [xibContents objectAtIndex:0]; // Safer than objectAtIndex:0
//UIView *subView=[view.subviews objectAtIndex:0];
[view setFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)];
CGRect tempFrame=view.frame;
tempFrame.size.width=300;//change acco. how much you want to expand
tempFrame.size.height=350;
[UIView beginAnimations:@"" context:nil];
[UIView setAnimationDuration:0.2];
view.frame=tempFrame;
//[UIView commitAnimations];
[view setFrame:CGRectMake(10.0f, 90.0f, 300.0f, 350.0f)];
[view setBackgroundColor:
[UIColor colorWithPatternImage:
[UIImage imageNamed:@"Register_bg"]]];
[UIView commitAnimations];
[view removeFromSuperview];
[self.view addSubview:view];
I am using UIStoryboard
, and made this xib
and showed from following code.
How can I remove this view. I have a UIButton
, whose IBAction
is being called.
Thanks
Upvotes: 0
Views: 7581
Reputation: 3663
It's too simple to remove any view from its super view just type
[yourview removeFromSuperview];
If you declaring view as a property, then use like below.
[self.yourview removeFromSuperview];
Upvotes: 2
Reputation: 57050
Keep a weak reference to the view (either a property or an instance variable) and call removeFromSuperview
like so:
[self.viewToRemove removeFromSuperview];
Upvotes: 9