大头针

系统大头针

大头针基本操作

// 添加一个大头针
- (void)addAnnotation:(id <MKAnnotation>)annotation;

// 添加多个大头针
- (void)addAnnotations:(NSArray *)annotations;

// 移除一个大头针
- (void)removeAnnotation:(id <MKAnnotation>)annotation;

// 移除多个大头针
- (void)removeAnnotations:(NSArray *)annotations;

新建大头针模型

@interface MyAnnotation : NSObject <MKAnnotation>
// 坐标位置 
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
// 标题
@property (nonatomic, copy) NSString *title; 
// 子标题
@property (nonatomic, copy) NSString *subtitle; 
@end

添加大头针

MyAnnotation *anno = [[MyAnnotation alloc] init];
anno.title = @"北京";
anno.subtitle = @"空气清新的地方";
anno.coordinate = CLLocationCoordinate2DMake(40, 116);
[self.mapView addAnnotation:anno];

自定义大头针

方式: 设置mapView的代理, 实现代理方法

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

注意:
1> 如果返回nil,显示出来的大头针就采取系统的默认样式
2> 标识用户位置的蓝色发光圆点,它也是一个大头针,当显示这个大头针时,也会调用代理方法
3> 因此,需要在代理方法中分清楚(id )annotation参数代表自定义的大头针还是蓝色发光圆点

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值