2014-09-03 203 views
2

嗨,我使用谷歌地圖中,​​我想用標誌像下面的圖片 marker i wantIOS谷歌地圖自定義標記

我已經做了代碼

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; 

它給我輸出

getting output

誰能告訴我爲什麼這黑色背景來了?如何解決?

回答

0

我認爲你的問題是設置圖像作爲你的看法的背景。

markerview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"glow-marker2.png"]]; 

我建議,使這一觀點的背景,爲透明色,並設置opaque=NO,並設置圖像的ImageView並添加此圖像作爲子視圖您markerview

希望您發出將要解決。

0

我認爲這個問題是當你讓你的UIView圖像。請嘗試下面的代碼

- (UIImage *) imageWithView:(UIView *)view 
{ 
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 1.0); 
    [view.layer renderInContext:UIGraphicsGetCurrentContext()]; 

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); 

    UIGraphicsEndImageContext(); 

    return img; 
}