alex
alex

Reputation: 5002

Add MKUserTrackingBarButtonItem to UIView

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

MKUserTrackingBarButtonItem Icons

Thanks for your help.

Upvotes: 4

Views: 3098

Answers (3)

Ortwin Gentz
Ortwin Gentz

Reputation: 54101

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

Upvotes: 1

aopsfan
aopsfan

Reputation: 2441

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?

Upvotes: 5

aopsfan
aopsfan

Reputation: 2441

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?

Upvotes: 0

Related Questions