0
我想在Xcode(objetive-c)上的每个地图引脚的leftCalloutAccessoryView中获取不同的图像。我在网上寻找其他答案,但我没有找到这个(只有如何改变引脚图像)。但是我想改变引脚标题左侧的引脚图像。有人能帮我吗?非常感谢你。在leftCalloutAccessoryView地图中显示不同的图像Xcode
这是我RestMapPin.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface RestMapPin : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, copy) NSString *image;
@end
这是我RestMapPin.m:
#import "RestMapPin.h"
@implementation RestMapPin
@synthesize coordinate, title, subtitle, image;
@end
这是我MapViewController.h:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapViewController : UIViewController {
MKMapView *mapView;
}
@property (weak, nonatomic) IBOutlet UIBarButtonItem *barButton;
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@property(nonatomic, retain) CLLocationManager *locationManager;
@end
这是我的MapViewController。 m:
#import "MapViewController.h"
#import "SWRevealViewController.h"
#import "RestMapPin.h"
#import "RestViewController.h"
@interface MapViewController()
@end
@implementation MapViewController
@synthesize mapView;
- (void)viewDidLoad {
[super viewDidLoad];
_barButton.target = self.revealViewController;
_barButton.action = @selector(revealToggle:);
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
/*Babelia*/
MKCoordinateRegion region_Babelia = { {0.0, 0.0}, {0.0, 0.0}};
region_Babelia.center.latitude = 40.4234778;
region_Babelia.center.longitude = -3.686283000000003;
region_Babelia.span.longitudeDelta = 0.1f;
region_Babelia.span.latitudeDelta = 0.1f;
[mapView setRegion:region_Babelia animated:YES];
RestMapPin *ann_Babelia = [[RestMapPin alloc] init];
ann_Babelia.title = @"Babelia";
ann_Babelia.subtitle = @"Barrio de Salamanca";
ann_Babelia.coordinate = region_Babelia.center;
[mapView addAnnotation:ann_Babelia];
/*Bacira*/
MKCoordinateRegion region_Bacira = { {0.0, 0.0}, {0.0, 0.0}};
region_Bacira.center.latitude = 40.43375390000001;
region_Bacira.center.longitude = -3.699036299999989;
region_Bacira.span.longitudeDelta = 0.1f;
region_Bacira.span.latitudeDelta = 0.1f;
[mapView setRegion:region_Bacira animated:YES];
RestMapPin *ann_Bacira = [[RestMapPin alloc] init];
ann_Bacira.title = @"Bacira";
ann_Bacira.subtitle = @"Chamberí";
ann_Bacira.coordinate = region_Bacira.center;
[mapView addAnnotation:ann_Bacira];
}
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
if(annotation != mapView.userLocation) {
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil)
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:@"[email protected]"];
}
else {
//[mapView.userLocation setTitle:@"I am here"];
}
UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"[email protected]"]];
pinView.leftCalloutAccessoryView = leftIconView;
leftIconView.layer.cornerRadius = 6;
leftIconView.clipsToBounds = YES;
leftIconView.layer.borderWidth = 1;
return pinView;
}
@end
我知道这是类似于viewForAnnotation方法的代码的东西:
UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"[email protected]"]];
pinView.leftCalloutAccessoryView = leftIconView;
但我不知道如何去改变它是每个地图针不同(“Babelia”和“Bacira” )。 非常感谢您的回复!
它的伟大工程。非常感谢你! –