Reputation: 1062
I have a ViewController file and in this ViewController file, I create programmatically a view which it takes all the available place on the window.
Now, I want to make a view with the Storyboard. I put this view (in my case a button) on my Storyboard.
And when I launch my application, I cannot see my button because it is under the view which I created before programmatically.
Is this possible to have my Storyboard view above the other view ?
Thanks a lot !
Upvotes: 1
Views: 4185
Reputation: 1448
Yes, it's possible.
Looks like you use addSubview
method.
The problem that you encountered is that views added in such way overlay the existed views.
You can either bring button to front with bringSubviewToFront
or use insertSubview:belowSubview
and insertSubview:aboveSubview
to fix such issues. In both cases you'll need your button stored in property.
Upvotes: 1
Reputation: 1751
It sort of depends on your view hierarchy setup.
I'm assuming this:
A - View controller view
| B - Your button
| C - Programmatically added fullscreen view
In the above case you could do something like this:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view bringSubviewToFront:self.button];
}
Point is bringSubviewToFront:
moves a subview to the top of the hierarchy.
Upvotes: 1
Reputation: 95
So you will have to create an outlet for the button (connect the button in storyboard to the name given to it in your .swift file) Once you have added the view programmatically, you just have to do
self.view.bringSubviewToFront(button)
Assuming that button is the name of the outlet. This line will be added after adding the view programatically.
Upvotes: 0