Bring UIButton to the front layer

I know that there is a way to bring the view to the front of the hierarchy. However, there is a way to bring the button that I placed in the story and call a function that will make this button the top layer so that it is not hidden by any other added elements that are not in the story board.

Thanks,

+8
ios objective-c uibutton
source share
4 answers

I'm late for this question, but not too late to answer Swift 3

Swift 3

view.bringSubview(toFront: theButton) 
+5
source share

UIButton is a UIView, so you can call -bringSubviewToFront: on your button instance.

+4
source share

uiview displayed in the order in which they are stacked. you can change this to say that you need to insert a new uiview , which in your case is uibutton.

one way to do this is by creating an IBOUtlet for uibutton and adding this button instance as a subset / new view over an existing uiview .

CODE:

[self.view insertSubview:<new Uiview> aboveSubview:<existing uiview>];

Also, if you cannot determine the uiview order, you can check that in xcode

  • When you start a project in debug mode, there is a button in the debug window (highlighted in the image below) Debug viewing hierarchy , you need to click it. (highlighted below).

Debug window toolbar

  • After that, you can see the entire rendering of the views on the screen in the current instance, using this function, which you can understand is that your new uiview is in the uiview stack order (shown below).

User Interface Presentation Hierarchy

Happy coding :)

+1
source share

Swift

The following works fine if the view you are working with is hidden views that are in the same view.

 superview?.bringSubviewToFront(self) 
+1
source share

All Articles