MKAnnotationView khusus dengan bingkai, ikon, dan gambar

Saya telah mencari solusi serupa tentang cara mendesain MKAnnotationView khusus seperti ini.

masukkan deskripsi gambar di sini

Saya telah membuat subkelas MKAnnotation dan saya dapat menambahkan gambar bernama F.png. F.png adalah gambar bingkai seperti yang ditunjukkan pada gambar. yang saya inginkan adalah menambahkan gambar batin. (berwarna Biru pada gambar yang saya gambar)

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{    
if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if(annotationView)
    return annotationView;
else
{
    MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
    annotationView.canShowCallout = YES;
    annotationView.image = [UIImage imageNamed:[NSString stringWithFormat:@"F.png"]];        
    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton addTarget:self action:@selector(writeSomething:) forControlEvents:UIControlEventTouchUpInside];
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];

    annotationView.rightCalloutAccessoryView = rightButton;
    annotationView.canShowCallout = YES;
    annotationView.draggable = NO;
    return annotationView;
}
return nil;
}

person Kassem    schedule 09.05.2012    source sumber
comment
satu-satunya hal yang dapat saya lakukan adalah mengubah gambar anotasi, tetapi saya tidak dapat mengatur cara menambahkan gambar, bingkai di atasnya dan ikon di pojok kiri bawah. saya dapat membuat 4 bingkai dengan 4 ikon berbeda karena saya memiliki 4 anotasi berbeda. sedikit bagaimana saya bisa menyematkan ikon di dalam bingkai.   -  person Kassem    schedule 09.05.2012
comment
Apakah Anda mencoba membuat subkelas tampilan anotasi?   -  person EmilioPelaez    schedule 09.05.2012
comment
saya telah memperbarui pertanyaan dengan informasi lebih lanjut.   -  person Kassem    schedule 09.05.2012


Jawaban (1)


di sini di kode Anda

else
{
    MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
    annotationView.canShowCallout = YES;

    //change here
    annotationView.image = [UIImage imageNamed:[NSString stringWithFormat:@"F.png"]];  

    UIImage *frame = [UIImage imageNamed:[NSString stringWithFormat:@"F.png"];
    UIImage *image = theImageInFrameInner;

    UIGraphicsBeginImageContext(CGSizeMake(pin.size.width, pin.size.height));

    [frame drawInRect:CGRectMake(0, 0, frame.size.width, frame.size.height)];
    [image drawInRect:CGRectMake(2, 2, 60, 60)]; // the frame your inner image
    //maybe you should draw the left bottom icon here, 

    //then set back the new image, done
    annotationView.image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton addTarget:self action:@selector(writeSomething:) forControlEvents:UIControlEventTouchUpInside];
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];

    annotationView.rightCalloutAccessoryView = rightButton;
    annotationView.canShowCallout = YES;
    annotationView.draggable = NO;
    return annotationView;
}
person adali    schedule 10.05.2012