您好我正在使用谷歌地图,我想使用像下面的图像标记
我已完成代码
UIView *markerview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 55, 102)];
markerview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"glow-marker2.png"]];
UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake(4, 4, 47, 70)];
imgview.backgroundColor = [UIColor whiteColor];
imgview.contentMode = UIViewContentModeScaleAspectFit;
imgview.image = img;
imgview.layer.cornerRadius = 7;
imgview.layer.masksToBounds = YES;
[markerview addSubview:imgview];
marker.icon = [self imageWithView:markerview];
marker.map = mapview;
它给我输出
谁能告诉我为什么这个黑色背景会来?怎么解决?
答案 0 :(得分:0)
我认为问题在于你将UIView设为图像。尝试以下代码
- (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 1.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
答案 1 :(得分:0)
我认为您的问题是将图片设置为您视图的背景。
markerview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"glow-marker2.png"]];
我建议将背景视为一种清晰的颜色并设置opaque=NO
并将图像设置为imageview,并将此图像添加为markerview
的子视图
希望你能解决问题。