你知道地图应用程序左下角的小位置按钮吗?有人知道我在哪里可以找到那个吗?我查看了 UIButtonType 和 UITabBarSystemItem 但出现了空白。
我更喜欢使用系统映像或系统其他东西,以帮助确保与其他系统功能的一致性。
看看https://github.com/myell0w/MTLocation
我模仿了 Google Maps 的 Locate Me - Button,包括 4 种不同的状态以及在状态之间切换时完成的动画。
您可以尝试使用MKUserTrackingBarButtonItem 它提供与地图应用程序上的跟踪按钮相同的功能。这是一些相同的代码。
MKUserTrackingBarButtonItem *trackButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.mapView];
NSMutableArray *items = [[NSMutableArray alloc] initWithArray:self.bottomToolbar.items];
[items insertObject:trackButton atIndex:0];
[self.bottomToolbar setItems:items];
请注意,在 4.0 中,Maps.app 按钮中“定位我”按钮的外观发生了变化。更进一步,+[UIimage kitImageNamed:]
已经消失了,-[UIBarbuttonItem initWithBarButtonSystemItem:]
使用未记录的标识符 100 调用将返回旧式图形。
(警告:未记录的功能,将被 AppStore 拒绝,等等等等)
位置按钮可以通过
UIBarButtonItem* item = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:100
target:... action:...];
如果您只想要图像,请保存返回的结果
UIImage* img = [UIImage kitImageNamed:@"UIButtonBarLocate.png"];
我创建了自己的图像,Apple 接受了它(与使用搜索图像进行缩放相反)。
http://glyphish.com/图标库有可用的位置按钮。
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];
使用此代码示例将其保存为可以在项目中使用的文件!
希望这有帮助。
我不太确定这是系统映像。Apple 应用程序中的许多图像/按钮仅特定于该应用程序,而这个看起来就是这样。