Пользовательский MKAnnotationView с рамкой, значком и изображением

Я искал похожее решение о том, как создать собственный MKAnnotationView, подобный этому.

введите здесь описание изображения

Я создал подкласс MKAnnotation и смог добавить изображение с именем F.png. F.png — это изображение кадра, как показано на рисунке. я хочу добавить внутреннее изображение. (цвет синий на картинке, которую я рисую)

- (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 источник
comment
единственное, что я смог сделать, это изменить изображение аннотации, но мне не удалось добавить изображение, рамку поверх него и значок в левом нижнем углу. Я могу сделать 4 кадра с 4 разными иконками, так как у меня есть 4 разных аннотации. немного, как я могу вставить значок в рамку.   -  person Kassem    schedule 09.05.2012
comment
Вы пытались создать подкласс представления аннотации?   -  person EmilioPelaez    schedule 09.05.2012
comment
я обновил вопрос с дополнительной информацией.   -  person Kassem    schedule 09.05.2012


Ответы (1)


здесь в вашем коде

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