百度地图(自定义标签、气泡)

来源:互联网 发布:知乎的收藏夹在哪 编辑:程序博客网 时间:2024/04/30 04:14


昨天写了一篇文章是关于百度地图定位的,刚好最近在写关于地图的模块,把工作中用到的记录下来,边学边用,也挺好的(不过太寂寞,不知道干什么)

今天就写一些自定义标签,弹出的气泡方法

挺简单的,直接上代码吧

if([annotationisKindOfClass:[BMKPointAnnotationclass]]) {
       
BMKPinAnnotationView*newAnnotation = [[BMKPinAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:@"myAnnotation"];
        newAnnotation.
pinColor=BMKPinAnnotationColorPurple;
        newAnnotation.
animatesDrop=YES;
       
        
//设置弹出气泡图片
       
UIView*popView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,240,280)];
        popView.
backgroundColor= [UIColorwhiteColor];
       
//image
       
UIImageView*image = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"moren"]];
        image.
frame=CGRectMake(0,0,240,140);
        [popView
addSubview:image];
       
//image1 text1
       
UIImageView*image1 = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"yingpian2_ico_"]];
        image1.
frame=CGRectMake(10,150,20,20);
        [popView
addSubview:image1];
       
       
UILabel*driverName = [[UILabelalloc]initWithFrame:CGRectMake(40,145,100,30)];
        driverName.
text=@"绝地逃亡";
        driverName.
font= [UIFontboldSystemFontOfSize:14];
        driverName.
textAlignment=NSTextAlignmentLeft;
        [popView
addSubview:driverName];
       
//text2
       
UILabel*name2 = [[UILabelalloc]initWithFrame:CGRectMake(10,185,100,20)];
        name2.
text=@"成龙";
        name2.
font= [UIFontboldSystemFontOfSize:13];
        name2.
textAlignment=NSTextAlignmentLeft;
        [popView
addSubview:name2];
       
//text3
       
UILabel*name3 = [[UILabelalloc]initWithFrame:CGRectMake(10,210,100,20)];
        name3.
text=@"中国云南";
        name3.
font= [UIFontsystemFontOfSize:13];
        name3.
textAlignment=NSTextAlignmentLeft;
        [popView
addSubview:name3];
       
//button
       
UIButton*btn = [UIButtonbuttonWithType:UIButtonTypeCustom];
        btn.
frame=CGRectMake(0,250,240,30);
        [btn
setTitle:@"进入"forState:UIControlStateNormal];
        btn.
backgroundColor= [UIColorcolorWithRed:236/255.0green:85/255.0blue:77/255.0alpha:1];
//        [btn setBackgroundImage:[UIImage imageNamed:@"wo_beijing"] forState:UIControlStateNormal];
        [popView
addSubview:btn];
       
       
BMKActionPaopaoView*pView = [[BMKActionPaopaoViewalloc]initWithCustomView:popView];
        pView.
frame=CGRectMake(0,0,240,280);
        ((
BMKPinAnnotationView*)newAnnotation).paopaoView=nil;
        ((
BMKPinAnnotationView*)newAnnotation).paopaoView= pView;

       
returnnewAnnotation;
    }




最后效果图,点击大头针出现


我创建了一个交流群,大家可以加一下一起交流  进修Android~iOS+“ 群:237311061  大神在里面,而且群里面会分享有一些iOS课件






0 0