I am using Mapbox SDK (SWIFT) and created my custom map. I added a button and image on the map in storyboard but when I run the application it seems like it is hidden behind. I tried everything including view.bringSubview(toFront:UIimage) and I can't use this function with a UIButton. I even tried sending the map to the backView but it messes up my custom map and still don't see my image or button. Please help! Thank you.
How to bring UIButton to front of Mapbox view
1.7k Views Asked by marcoder AtThere are 4 best solutions below
On
Please check below image make sure your Views hierarchy as followed your button should be last in hierarchy
Here is my output
or if you have button inside view then you can set it to front as
Self.view.bringSubviewToFront(button) or button.superview?.bringSubviewToFront(button)
Make sure you button is not hidden in Storyboard and when your app is running then Capture user Interface and check layers of your Storyboard.
On
I couldn't change my view hierarchy's for my mapview, so I took a different approach.
I had my mapview created in my viewDidLoad function with let mapView = MGLMapView(...), my mapview was then made visible with the code view.addSubview(mapView). I had to make my button visible similarly.
First I inserted an IBOutlet into my ViewController class
@IBOutlet weak var MyButton: UIButton!
Which referenced the button I placed over my mapView in storyboard. I then added my button to the view by adding
view.addSubview(MyButton)
Right after adding my mapView.



You need to bring it to top of the view