iOS 高德地图开发,怎么为大头针的背景图添加不同的字
1个回答
展开全部
// 自定义大头针标注
- (MAAnnotationView *)mapView:(MAMapView *)mapView
viewForAnnotation:(id<MAAnnotation>)annotation {
if ([annotation isKindOfClass:[MAPointAnnotation class]]) {
static NSString *reuseIndetifier = @"annotationReuseIndetifier";
MAAnnotationView *annotationView = (MAAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
if (annotationView == nil) {
annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
}
annotationView.draggable=YES;
annotationView.canShowCallout=YES;
annotationView.image = [UIImage imageNamed:@"mark_bg"];
//在大头针上绘制文字
UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(5, 3, 15, 10)];
lable.font=[UIFont systemFontOfSize:12];
lable.textColor=[UIColor orangeColor];
NSArray *titleArray=[NSArray arrayWithObjects:@"A",@"B",@"C", nil];
for (int a=0;a<titleArray.count;a++) {
lable.text=titleArray[a];
NSLog(@"a is %d",a);
NSLog(@"text is %@",lable.text);
}
[annotationView addSubview:lable];
- (MAAnnotationView *)mapView:(MAMapView *)mapView
viewForAnnotation:(id<MAAnnotation>)annotation {
if ([annotation isKindOfClass:[MAPointAnnotation class]]) {
static NSString *reuseIndetifier = @"annotationReuseIndetifier";
MAAnnotationView *annotationView = (MAAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
if (annotationView == nil) {
annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
}
annotationView.draggable=YES;
annotationView.canShowCallout=YES;
annotationView.image = [UIImage imageNamed:@"mark_bg"];
//在大头针上绘制文字
UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(5, 3, 15, 10)];
lable.font=[UIFont systemFontOfSize:12];
lable.textColor=[UIColor orangeColor];
NSArray *titleArray=[NSArray arrayWithObjects:@"A",@"B",@"C", nil];
for (int a=0;a<titleArray.count;a++) {
lable.text=titleArray[a];
NSLog(@"a is %d",a);
NSLog(@"text is %@",lable.text);
}
[annotationView addSubview:lable];
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询