I have a UIButton
and a UIView
that animates, sliding down when the UIButton
is pressed. The problem is that the UIView
obscures the UIButton
. I'd like the UIButton
to always remain on top.
I tried this in the viewDidLoad
:
[self.view bringSubviewToFront:categoryBtn];
doesn't work though.
thanks for any help
After Add any UIView
or any other view on your this mainview , after that just add your this line for brings as a supeview for button
[self.view bringSubviewToFront:categoryBtn];
For Example on button action event you add any view then use code like bellow..
-(IBAction)yourButton_Clicked:(id)sender
{
///Add some code or view here and then after write this line here see bellow line
[self.view bringSubviewToFront:categoryBtn];
}
The other answer is will work, but this is exactly the kind of thing "insertSubview: belowSubview" was added for.
[self.view insertSubview:myNewView belowSubview:_categoryBtn];
This allows you to add the new view below the button on the view stack instead of adding it above the button and then rearranging the views.
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