IOS百度地圖氣泡內容自定義

 最簡單,最直接的方法。。。

自定義一個 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;

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章