I am trying to put a button in the corner of my MKMapView to control whether the map stays locked on to the user's location. What I have in mind is to create a UIView
with a button on and add it over my MKMapView
(not as an annotation or something) I can't figure this out with Interface Builder.
How can I add this button programmatically?
Controlling whether it actually follows the user etc. is already sorted - just need the button for it.
It looks like you are directly setting the controller's
view
outlet to anMKMapView
object rather than aUIView
object containing theMKMapView
object. You cannot drop the button in such case on top of theMKMapView
object in theIB
. There are two ways you can deal with this,IB
. This needn't be on top of theMKMapView
object. Set the outlet to, say, abutton
property. Then inviewDidLoad
do[self.view addSubview:self.button];
after setting thebutton
'sframe
. (or)UIView
object in IB and put theMKMapView
object inside it. Set the controller'sview
to this containerUIView
object. Later drop the button on top of theMKMapView
object and set it to its appropriate location.