Adding an UIView over a MKMapView
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 fig开发者_StackOverflow社区ure 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 an MKMapView object rather than a UIView object containing the MKMapView object. You cannot drop the button in such case on top of the MKMapView object in the IB. There are two ways you can deal with this,
- Declare an outlet for the button and drop the button in the
IB. This needn't be on top of theMKMapViewobject. Set the outlet to, say, abuttonproperty. Then inviewDidLoaddo[self.view addSubview:self.button];after setting thebutton'sframe. (or) - Drop a new
UIViewobject in IB and put theMKMapViewobject inside it. Set the controller'sviewto this containerUIViewobject. Later drop the button on top of theMKMapViewobject and set it to its appropriate location.
加载中,请稍侯......
精彩评论