4

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.

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
alex
  • 4,922
  • 7
  • 37
  • 51

3 Answers3

5

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?

Community
  • 1
  • 1
aopsfan
  • 2,451
  • 19
  • 30
  • Awesome... that worked well! Do you know if this could cause a rejection from the AppStore? – alex Nov 14 '11 at 21:18
  • 2
    I don't think so...here's a list of things that Apple doesn't like: http://mobileorchard.com/avoiding-iphone-app-rejection-from-apple/ . This whole thing may violate the Human Interface Guidelines, but I doubt it. – aopsfan Nov 14 '11 at 22:22
1

Starting in iOS 11, there's MKUserTrackingButton which is a UIView subclass.

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
0

Here's a link so you can create an image out of the button. You probably want to do this as it enters multiple states:

Create UIImage from shadowed view while retaining alpha?

Community
  • 1
  • 1
aopsfan
  • 2,451
  • 19
  • 30
  • Thanks for the link. I looked at it, but I think my problem is different. I can't access the `UIImageView` inside the button. Is there a way to extract just the image (the arrow or arrow+heading in this case) out of a `UIBarItem`? – alex Nov 14 '11 at 13:20
  • button.image should return the image used for the button but returns nil... see http://developer.apple.com/library/ios/#documentation/uikit/reference/UIBarItem_Class/Reference/Reference.html – alex Nov 14 '11 at 13:46
  • `button.image` is supposed to return just the image, not the view...I guess Apple is using a different method to configure their `MKUserTrackingBarButtonItem`. – aopsfan Nov 14 '11 at 17:47