iPhone location button

对着背影说爱祢 提交于 2019-12-03 02:48:43
myell0w

Have a look at https://github.com/myell0w/MTLocation

I mimiced Google Maps' Locate Me - Button, including 4 different states and the animation that is done when switching between states.

You can try using MKUserTrackingBarButtonItem It provides the same functionality as the track button on the Map app. Here is some same code.

MKUserTrackingBarButtonItem *trackButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.mapView];
NSMutableArray *items = [[NSMutableArray alloc] initWithArray:self.bottomToolbar.items];
[items insertObject:trackButton atIndex:0];
[self.bottomToolbar setItems:items];

Please note that in 4.0, the appearance of the "locate me" button in Maps.app button has changed. Further on, +[UIimage kitImageNamed:] is gone, and calling -[UIBarbuttonItem initWithBarButtonSystemItem:] with undocumented identifier 100 will return old-style graphics.

(Warning: undocumented feature, will be rejected by AppStore, blah blah blah)

The location button can be accessed with

UIBarButtonItem* item = [[UIBarButtonItem alloc]
                         initWithBarButtonSystemItem:100
                                              target:... action:...];

If you just want the image, save the result returned by

UIImage* img = [UIImage kitImageNamed:@"UIButtonBarLocate.png"];

I created my own image, and Apple accepted it (in contrast of using the search image for zooming purposes).

http://glyphish.com/ icon library has location button available.

I wouldn't be so sure that it's a system image. Many images/buttons in Apple's applications are specific to that application only, and this one looks to be that way.

UIImage* img = [UIImage kitImageNamed:@"UIButtonBarLocate.png"];
// Get the location of the Documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) ;
NSString *imagePath = [paths objectAtIndex:0] ;
NSString *filename = @"test.png" ; 
NSString *filepath = [NSString stringWithFormat:@"%@/%@", imagePath, filename] ;

// Save the image 
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(img)];
[imageData writeToFile:filepath atomically:YES];

use this sample of code to save it as a file that you'll be able to use in your project!

Hope this help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!