百度地图自定义大头针图片和添加标注
2017-02-25 17:21
369 查看
// 根据anntation生成对应的View
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView
viewForAnnotation:(id <BMKAnnotation>)annotation
{
NSString * AnnotationViewID = [NSString stringWithFormat:@"renameMark%d",map_i];
newAnnotation = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
// 设置颜色
((BMKPinAnnotationView *)newAnnotation).pinColor = BMKPinAnnotationColorPurple;
// 从天上掉下效果
((BMKPinAnnotationView *)newAnnotation).animatesDrop = NO;
// 设置可拖拽
((BMKPinAnnotationView *)newAnnotation).draggable = YES;
//设置大头针图标
((BMKPinAnnotationView *)newAnnotation).image =
[UIImage imageNamed:@"icon"];
UIView * popView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 53)];
//设置弹出气泡图片
UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"yuanju_gnnr_icon"]];
image.frame = CGRectMake(0, 0, 100, 60);
[popView addSubview:image];
//自定义显示的内容
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 7,
b00d
100, 11)];
label.text = @"医院";
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:11];
label.textColor = [self hexStringToColor:@"#333333"];
label.textAlignment = NSTextAlignmentLeft;
[popView addSubview:label];
UILabel * locationLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 25, 100, 18)];
locationLabel.text = [self.userDefaults objectForKey:@"loc"];
locationLabel.backgroundColor = [UIColor clearColor];
locationLabel.font = [UIFont systemFontOfSize:18];
locationLabel.textColor = [self hexStringToColor:@"#333333"];
locationLabel.textAlignment = NSTextAlignmentLeft;
[popView addSubview:locationLabel];
//根据获取到的地址来重新设置气泡的大小
//地址标签
CGRect locationRect = locationLabel.frame;
locationRect.size.width = [locationLabel sizeThatFits:CGSizeZero].width;
locationLabel.frame = locationRect;
//父view宽度
CGRect popRect = popView.frame;
popRect.size.width = [locationLabel sizeThatFits:CGSizeZero].width + 20;
popView.frame = popRect;
//设置弹出气泡图片
image.frame = popView.frame;
BMKActionPaopaoView * pView = [[BMKActionPaopaoView alloc]initWithCustomView:popView];
pView.frame = CGRectMake(0, 0, 100, 60);
((BMKPinAnnotationView *)newAnnotation).paopaoView = nil;
((BMKPinAnnotationView *)newAnnotation).paopaoView =
pView;
map_i++;
return newAnnotation;
}
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView
viewForAnnotation:(id <BMKAnnotation>)annotation
{
NSString * AnnotationViewID = [NSString stringWithFormat:@"renameMark%d",map_i];
newAnnotation = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
// 设置颜色
((BMKPinAnnotationView *)newAnnotation).pinColor = BMKPinAnnotationColorPurple;
// 从天上掉下效果
((BMKPinAnnotationView *)newAnnotation).animatesDrop = NO;
// 设置可拖拽
((BMKPinAnnotationView *)newAnnotation).draggable = YES;
//设置大头针图标
((BMKPinAnnotationView *)newAnnotation).image =
[UIImage imageNamed:@"icon"];
UIView * popView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 53)];
//设置弹出气泡图片
UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"yuanju_gnnr_icon"]];
image.frame = CGRectMake(0, 0, 100, 60);
[popView addSubview:image];
//自定义显示的内容
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 7,
b00d
100, 11)];
label.text = @"医院";
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:11];
label.textColor = [self hexStringToColor:@"#333333"];
label.textAlignment = NSTextAlignmentLeft;
[popView addSubview:label];
UILabel * locationLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 25, 100, 18)];
locationLabel.text = [self.userDefaults objectForKey:@"loc"];
locationLabel.backgroundColor = [UIColor clearColor];
locationLabel.font = [UIFont systemFontOfSize:18];
locationLabel.textColor = [self hexStringToColor:@"#333333"];
locationLabel.textAlignment = NSTextAlignmentLeft;
[popView addSubview:locationLabel];
//根据获取到的地址来重新设置气泡的大小
//地址标签
CGRect locationRect = locationLabel.frame;
locationRect.size.width = [locationLabel sizeThatFits:CGSizeZero].width;
locationLabel.frame = locationRect;
//父view宽度
CGRect popRect = popView.frame;
popRect.size.width = [locationLabel sizeThatFits:CGSizeZero].width + 20;
popView.frame = popRect;
//设置弹出气泡图片
image.frame = popView.frame;
BMKActionPaopaoView * pView = [[BMKActionPaopaoView alloc]initWithCustomView:popView];
pView.frame = CGRectMake(0, 0, 100, 60);
((BMKPinAnnotationView *)newAnnotation).paopaoView = nil;
((BMKPinAnnotationView *)newAnnotation).paopaoView =
pView;
map_i++;
return newAnnotation;
}
相关文章推荐
- 百度地图添加多个大头针自定义图片
- iOS-百度地图添加标注自定义气泡
- iOS - 百度地图最基本操作(定位,手势添加自定义标注)
- 百度地图上自定义添加一个标注
- IOS 设置百度地图自定义标注图片,自定义泡泡
- iOS 百度地图_自定义Annotation大头针_修改大头针图片
- Android 百度地图添加自定义marker(覆盖物)不显示图片的解决方法
- iOS 百度地图_自定义Annotation大头针_修改大头针图片
- 自定义添加标注(大头针)样式,并使其适应屏幕
- 百度地图大头针图片的自定义
- UITabBarView 添加自定义图片
- ecshop更换升级FCKeditor编辑器到Kindeditor,支持图片批量上传,和百度地图添加
- FlexViewer3.4中CompositeSymbol复合型标注中添加图片与文字后第一次点击后不显示图片,二次点击后才显示
- 在信息窗口添加图片按钮(百度地图)
- 百度地图SDK2.1.1的自定义图标标注
- 百度地图拖拽设置自定义坐标demo3个(后台添加、修改,前台显示)
- 百度地图 gps转换百度坐标 添加自定义标签 (标记)
- 自定义按钮并添加点击事件&自定义图片并添加点击事件
- iOS 之 使用百度地图 (删除地图页面所有自己添加的标注)
- UEditor中为图片上传等添加自定义参数