leftcalloutaccessoryView获取整个注释视图

时间:2014-02-24 10:48:31

标签: ios objective-c mkmapview mkannotation mkannotationview

我想在leftaccessoryview中显示一张照片 就像下图 Like this

但我试图从照片库中设置图像,图像采用完整的注释视图,我根本没有看到标题 这是我用过的代码

 -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
 {


if([annotation isKindOfClass:[MKUserLocation class]])
   return nil;

static NSString *AnnotationIdentifier=@"AnnotationIdentifier";
MKPinAnnotationView *pinView=[[MKPinAnnotationView alloc ]initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
pinView.pinColor=MKPinAnnotationColorGreen;

UIButton *rbutton=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rbutton setTitle:annotation.title forState:UIControlStateNormal];
//[rbutton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView=rbutton;
if (image) {
    UIImageView *temp=[[UIImageView alloc]initWithImage:image];


    pinView.leftCalloutAccessoryView=temp;
}


return pinView;

}

imageUIImage我存储从图像选取器中拾取的图像。 我把它作为输出。 enter image description here

1 个答案:

答案 0 :(得分:1)

您是否尝试使用:

temp.contentMode = UIViewContentModeScaleAspectFit;

或尝试:

UIView *viewLeftAccessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, pinView.frame.size.height, pinView.frame.size.height)]

UIImageView *temp=[[UIImageView alloc] initWithFrame:CGRectMake(5, 5, pinView.frame.size.height- 10, pinView.frame.size.height -10)];
temp.image = image;
temp.contentMode = UIViewContentModeScaleAspectFit;

[viewLeftAccessory addView:temp];

pinView.leftCalloutAccessoryView=viewLeftAccessory;

希望这会有所帮助。

相关问题