在MKAnotationView Xcode中添加多行字幕

时间:2012-09-10 11:26:23

标签: iphone objective-c ios xcode ipad

我遇到在Xcode 4.2中显示多行MKAnnotion的问题

这是我的代码,它为注释显示单行字幕。

  -(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
    (id <MKAnnotation>)annotation {
    MKPinAnnotationView *pinView = nil; 
    if(annotation != mapView.userLocation) 
    {

        static NSString* MyAnnotationIdentifier = @"MyAnnotationIdentifier";
        MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
                                               initWithAnnotation:annotation     reuseIdentifier:MyAnnotationIdentifier] autorelease];        
        //--- adding pin color and animation
        customPinView.pinColor = MKPinAnnotationColorRed;
        customPinView.animatesDrop = YES;
        customPinView.canShowCallout = YES;              
        return customPinView;
    }
    else
    {
        pinView.annotation = annotation;
    }
    return pinView;
}

那么如何添加多行字幕?

提前致谢。

2 个答案:

答案 0 :(得分:0)

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{   
    MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"loc"];

    // Button
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 23, 23);
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

[button setImage:[UIImage imageNamed:yourImageName] forState:UIControlStateNormal];
[advertButton addTarget:self action:@selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];

annView.rightCalloutAccessoryView = button;


    // Image and two labels
    UIView *leftCAV = [[UIView alloc] initWithFrame:CGRectMake(0,0,23,23)];
    [leftCAV addSubview : yourImageView];
    [leftCAV addSubview : yourFirstLabel];
    [leftCAV addSubview : yourSecondLabel];
    annotationView.leftCalloutAccessoryView = leftCAV;

    annotationView.canShowCallout = YES;

    return pin;
}

另见此链接

How to display 2 lines of text for subtitle of MKAnnotation and change the image for the button on the right?

答案 1 :(得分:0)

使用此

sqlContext.sql

enter image description here