自定义一个 UIView
核心代码如下:
//改变标注图片和自定义气泡
-(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation
{
BMKAnnotationView *annotationView=[[BMKAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:@"myAnnotation"];
annotationView.image =[UIImageimageNamed:@"bike.gif"];
//自定义内容气泡
UIView *areaPaoView=[[UIViewalloc]initWithFrame:CGRectMake(0, 0, 200, 100)];
areaPaoView.layer.cornerRadius=8;
areaPaoView.layer.masksToBounds=YES;
areaPaoView.layer.contents =(id)[UIImageimageNamed:@"pao.png"].CGImage;//这张图片是做好的透明
//areaPaoView.backgroundColor=[UIColor whiteColor];
if ([annotation.titleisEqualToString:@"1"]) { //假设title的标题为1,那么就把添加上这个自定义气泡内容
UILabel * labelNo = [[UILabelalloc]initWithFrame:CGRectMake(10, 0, 200, 30)];
labelNo.text =[NSStringstringWithFormat:@"站点编号:%@"];
labelNo.textColor = [UIColorblackColor];
labelNo.backgroundColor = [UIColorclearColor];
[areaPaoViewaddSubview:labelNo];
UILabel * labelStationName = [[UILabelalloc]initWithFrame:CGRectMake(10, 20, 200, 30)];
labelStationName.text = [NSStringstringWithFormat:@"站点名称:昆山中学"];
labelStationName.textColor = [UIColorblackColor];
labelStationName.backgroundColor = [UIColorclearColor];
[areaPaoViewaddSubview:labelStationName];
UILabel * labelSumNum = [[UILabelalloc]initWithFrame:CGRectMake(10, 40, 200, 30)];
labelSumNum.text = [NSStringstringWithFormat:@"总桩数:30"];
labelSumNum.textColor = [UIColorblackColor];
labelSumNum.backgroundColor = [UIColorclearColor];
[areaPaoViewaddSubview:labelSumNum];
UILabel * labelBicycleNum = [[UILabelalloc]initWithFrame:CGRectMake(10, 60, 200, 30)];
labelBicycleNum.text = [NSStringstringWithFormat:@"可借车:20"];
labelBicycleNum.textColor = [UIColorblackColor];
labelBicycleNum.backgroundColor = [UIColorclearColor];
[areaPaoViewaddSubview:labelBicycleNum];
}
BMKActionPaopaoView *paopao=[[BMKActionPaopaoViewalloc]initWithCustomView:areaPaoView];
annotationView.paopaoView=paopao;
return annotationView;
}