IOS谷歌地图自定义标记
问题描述:
嗨,我使用谷歌地图中,我想用标志像下面的图片 IOS谷歌地图自定义标记
我已经做了代码
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;
它给我输出
谁能告诉我为什么这黑色背景来了?如何解决?
答
我认为你的问题是设置图像作为你的看法的背景。
markerview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"glow-marker2.png"]];
我建议,使这一观点的背景,为透明色,并设置opaque=NO
,并设置图像的ImageView并添加此图像作为子视图您markerview
希望您发出将要解决。
答
我认为这个问题是当你让你的UIView图像。请尝试下面的代码
- (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 1.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}