200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 百度地图自定义大头针图片和添加标注

百度地图自定义大头针图片和添加标注

时间:2021-01-19 07:25:57

相关推荐

百度地图自定义大头针图片和添加标注

//根据anntation生成对应的View

- (BMKAnnotationView*)mapView:(BMKMapView*)mapView viewForAnnotation:(id<BMKAnnotation>)annotation

{

NSString* AnnotationViewID = [NSStringstringWithFormat:@"renameMark%d",map_i];

newAnnotation= [[BMKPinAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:AnnotationViewID];

//设置颜色

((BMKPinAnnotationView*)newAnnotation).pinColor=BMKPinAnnotationColorPurple;

//从天上掉下效果

((BMKPinAnnotationView*)newAnnotation).animatesDrop=NO;

//设置可拖拽

((BMKPinAnnotationView*)newAnnotation).draggable=YES;

//设置大头针图标

((BMKPinAnnotationView*)newAnnotation).image= [UIImageimageNamed:@"icon"];

UIView* popView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,100,53)];

//设置弹出气泡图片

UIImageView*image = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"yuanju_gnnr_icon"]];

image.frame=CGRectMake(0,0,100,60);

[popViewaddSubview:image];

//自定义显示的内容

UILabel* label = [[UILabelalloc]initWithFrame:CGRectMake(10,7,100,11)];

label.text=@"医院";

label.backgroundColor= [UIColorclearColor];

label.font= [UIFontsystemFontOfSize:11];

label.textColor= [selfhexStringToColor:@"#333333"];

label.textAlignment=NSTextAlignmentLeft;

[popViewaddSubview:label];

UILabel* locationLabel = [[UILabelalloc]initWithFrame:CGRectMake(10,25,100,18)];

locationLabel.text= [self.userDefaultsobjectForKey:@"loc"];

locationLabel.backgroundColor= [UIColorclearColor];

locationLabel.font= [UIFontsystemFontOfSize:18];

locationLabel.textColor= [selfhexStringToColor:@"#333333"];

locationLabel.textAlignment=NSTextAlignmentLeft;

[popViewaddSubview:locationLabel];

//根据获取到的地址来重新设置气泡的大小

//地址标签

CGRectlocationRect = locationLabel.frame;

locationRect.size.width= [locationLabelsizeThatFits:CGSizeZero].width;

locationLabel.frame= locationRect;

//父view宽度

CGRectpopRect = popView.frame;

popRect.size.width= [locationLabelsizeThatFits:CGSizeZero].width+20;

popView.frame= popRect;

//设置弹出气泡图片

image.frame= popView.frame;

BMKActionPaopaoView* pView = [[BMKActionPaopaoViewalloc]initWithCustomView:popView];

pView.frame=CGRectMake(0,0,100,60);

((BMKPinAnnotationView*)newAnnotation).paopaoView=nil;

((BMKPinAnnotationView*)newAnnotation).paopaoView= pView;

map_i++;

returnnewAnnotation;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。