2011-06-19 11 views

答えて

0
- (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id <MKAnnotation>)annotation  { 
MKAnnotationView *pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"]; 

if (!pinView) { 
    pinView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"] autorelease]; 
    pinView.image = [UIImage imageNamed:@"SPOON4.png"]; 
    pinView.frame = CGRectMake(-30, 0, 70, 67.5); 
    //pinView.animatesDrop = YES; can't animate with custom pin images 
    pinView.canShowCallout = YES; 


    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    pinView.rightCalloutAccessoryView = rightButton; 

} else { 
    pinView.annotation = annotation; 
} 
if (annotation == mapView.userLocation){ 
    return nil; //default to blue dot 
} 
return pinView; 
} 
+0

それは働きます!ありがとう。 – dobiho

0

です。

あなたはあるようMKAnnotationViewクラス を使用したり、必要に応じてカスタム 動作を提供するために、それをサブクラス化することができます。このクラスの画像プロパティ を使用すると、アノテーションビュー の外観を直接サブクラス化せずに に設定できます。 も便利な というカスタムサブクラスを作成し、それを使用して アノテーションビューを既知の状態にすることができます。 の例では、MKPinAnnotationView サブクラスは、 の内容をピン画像に初期化します。

0

カスタムピンをフレーム付きのポートレートで置き換える必要があります。 Quartzでフレームを描画したり、フレームを第2の透明な画像として追加することができます。私はMKAnnotationViewに、次の第2の加算を行うだろう:

- (id)initWithAnnotation:(id <MKAnnotation>)annotation 
     reuseIdentifier:(NSString *)reuseIdentifier { 
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]; 
    if (self != nil) { 
     self.opaque = NO; 
     self.frame = CGRectMake(0,0, self.portraitImage.size.width, self.portraitImage.size.height); 
    } 
    return self; 
} 

- (void)drawRect:(CGRect)rect { 
     [self.frameImage drawInRect:CGRectMake(0, 0, frameImage.width, frameImage.height)]; 
     [self.portraitImage drawInRect:CGRectMake(0, 0, portraitImage.width, portraitImage.height)]; 
} 
関連する問題