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