简体   繁体   English

自定义标记图标 iOS 质量差

[英]Custom marker icon iOS bad quality

I'm trying to add an image to the marker.我正在尝试向标记添加图像。 How to achieve the best quality?如何达到最好的质量? As you can see the Google Map yourself increases it twice.正如您所看到的,谷歌地图自己将其增加了两倍。

地图

do you add an asset to you project or just one image?你是在你的项目中添加资产还是只添加一张图片?

So, you need to add asset of images (named like - bigMarker.png, bigMarker@2x.png, bigMarker@3x.png) to your project asset, like on screenshots.因此,您需要将图像资产(命名为 - bigMarker.png、bigMarker@2x.png、bigMarker@3x.png)添加到您的项目资产中,例如在屏幕截图上。 That works fine on iOS 9.这在 iOS 9 上运行良好。

项目中的 Assets.xcassets 大标记资产

And that my sample of code in viewDidLoad:我在 viewDidLoad 中的代码示例:

// Add custom position in Kansas
CustomAnnotation *annotation = [CustomAnnotation new];
annotation.title = @"Elevation Burger";
annotation.subtitle = @"The best buns...";
annotation.coordinate = CLLocationCoordinate2DMake(39.0119020f,-98.4842460f);
[self.myMap addAnnotation:annotation];

And this one in delegate:而这个代表:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {

    MKAnnotationView *annotationView = nil;
    if (annotation != mapView.userLocation) {
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
                                                      reuseIdentifier:nil];
        annotationView.canShowCallout = YES;
        annotationView.image = [UIImage imageNamed:@"bigMarker"];
        annotationView.leftCalloutAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"burgerBitmap"]];

        UIButton *accessoryButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        UIImage *disclosureButtonImage = [[UIImage imageNamed:@"disclosure"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [accessoryButton setImage:disclosureButtonImage forState:UIControlStateNormal];
        annotationView.rightCalloutAccessoryView = accessoryButton;
    }
    return annotationView;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM