IOS百度地圖氣泡內容自定義
最簡單,最直接的方法。。。
自定義一個 UIView
核心程式碼如下:
//改變標註圖片和自定義氣泡
-(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation
{
BMKAnnotationView *annotationView=[[BMKAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:@"myAnnotation"];
annotationView.image
//自定義內容氣泡
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.
[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;
}