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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值