Search code examples
iosios5iconsmapkitmkmapview

Add MKUserTrackingBarButtonItem to UIView


I am using a MKUserTrackingBarButtonItem to toggle my MKMapView's usertrackingMode.

  • Is it possible to move this button out of my Toolbar and place it on a normal UIView?
  • Of course, I could implement the behavior of the button myself. Do you have any resources for the icons used in this button?

MKUserTrackingBarButtonItem Icons

Thanks for your help.


Solution

  • So it seems there is no way to directly add any kind of bar button item to a UIView. We're going to have to subclass UIToolbar to make a totally invisible toolbar. Override - (void)drawRect:(CGRect)rect and put nothing, not even a [super drawRect]. Then, in init, run the following code:

    self = [super init];
    self.backgroundColor = [UIColor clearColor];
    self.opaque = NO;
    self.translucent = YES;
    
    return self;
    

    For more details, visit this link: Couldn't UIToolBar be transparent?