zoukankan      html  css  js  c++  java
  • MKMapView 自定义大头针的图片

    创建一个MKAnnotationView的子类,用于修改大头针的图片

    #import <MapKit/MapKit.h>
    #import <UIKit/UIKit.h>
    
    @interface CustomAnnotationView : MKAnnotationView
    
    @end
    1 - (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    2     self = [super initWithAnnotation:annotation reuseIdentifier:@"ID"];
    3     if (self) {
    4         self.backgroundColor = [UIColor clearColor];
    5     }
    6     
    7     return self;
    8 }

    在mapview的委托函数中,直接使用这个view初始化大头针

     1 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
     2     //判断系统大头针
     3     if ([annotation isKindOfClass:[mapView.userLocation class]]) {
     4         return nil;
     5     }
     6     
     7     CustomAnnotationView *pinView = (CustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"ID"];
     8     if (pinView == nil) {
     9         pinView = [[CustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"ID"];
    10         [pinView setDraggable:YES];
    11     }
    12     
    13     if ([[annotation title] isEqualToString:@"酒店1"]) {
    14         pinView.image = [UIImage imageNamed:@"1.PNG"];
    15     } else if ([[annotation title] isEqualToString:@"酒店2"]) {
    16         pinView.image = [UIImage imageNamed:@"2.png"];
    17     } else if ([[annotation title] isEqualToString:@"酒店3"]) {
    18         pinView.image = [UIImage imageNamed:@"3.png"];
    19     } else {
    20         pinView.image = [UIImage imageNamed:@"4.png"];
    21     }
    22 
    23     pinView.canShowCallout = YES;
    24     
    25     return pinView;
    26 }

    转载于:http://ningmengjiabing.blog.163.com/blog/static/204847198201292963224732/,有修改

  • 相关阅读:
    Linux下卸载openjdk,安装jdk
    dom4j移除节点不成功
    运费模版源码(.net)
    电子商城系统运费模板设计
    【转】js判断手机访问网页
    nopcommerce之一(结构分析)
    js阻止提交表单(post)
    s1=s1+1与s1+=1的区别
    .net中从GridView中导出数据到excel(详细)
    分布式事务中常见的三种解决方案
  • 原文地址:https://www.cnblogs.com/xiaochaozi/p/3685971.html
Copyright © 2011-2022 走看看