gpt4 book ai didi

ios - 更改MKMapView上的注释图钉颜色

转载 作者:行者123 更新时间:2023-12-01 16:36:48 25 4
gpt4 key购买 nike

我正在尝试通过覆盖以下内容来更改MKMapView上注释针的颜色:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// If it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;

// Handle any custom annotations.
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];
if (!pinView)
{
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
pinView.canShowCallout = YES;
pinView.pinColor = MKPinAnnotationColorGreen;
} else {
pinView.annotation = annotation;
}
return pinView;
}
return nil;
}

以下是相关方法:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

[self configureView];
}


- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {

// display map ????
PFGeoPoint *geoPoint = self.detailItem[@"location"];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(geoPoint.latitude,geoPoint.longitude);

MKPointAnnotation *annotation =[[MKPointAnnotation alloc] init];
annotation.coordinate = coordinate;

// remove previous annotation pin
if([self.mapView.annotations count] == 1) {
[self.mapView removeAnnotation:[self.mapView.annotations objectAtIndex:0]];
}

[self.mapView addAnnotation:annotation];
annotation.title = self.detailItem[@"text"];

MKCoordinateSpan span = {.latitudeDelta = 0.05, .longitudeDelta = 0.05};
MKCoordinateRegion region = {coordinate, span};
[self.mapView setRegion:region];

[self.mapView setCenterCoordinate:self.mapView.region.center animated:NO];

}

}

我的问题是,引脚注释颜色仍然显示为默认的红色而不是我想要的绿色。我在这里想念什么?

最佳答案

感谢@Anna,将以下行添加到-(void)configureView

self.mapView.delegate = self;

关于ios - 更改MKMapView上的注释图钉颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27468749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com