如何在图形页面与图像和标签在IPhone添加注释? [英] How to add annotation in Mapview with image and label in IPhone?

查看:141
本文介绍了如何在图形页面与图像和标签在IPhone添加注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的形象在这里

我在我的iPhone应用程序中使用的MKMapView。

I am using MKMapview in my iPhone app.

我怎样才能在指定标注值MKMapkit框架?

How can I assign values in annotation in MKMapkit Framework?

推荐答案

您可以使用自定义视图一个的UIView ,一是的UIImageView每个注释和一个标签来显示不同​​的值。这将在方法内完成 - (MKAnnotationView *)的MapView:(*的MKMapView)newMapView viewForAnnotation:(ID)newAnnotation 。你必须采取的UIView 两倍大小的透明颜色相对于的UIImageView ,使更多的precise视图放大和图形页面缩小。

You can use custom view for each annotation with one UIView, one UIImageView and one Label to display different value. This will be done within the method - (MKAnnotationView *)mapView:(MKMapView *)newMapView viewForAnnotation:(id )newAnnotation. You have to take UIView double in size with transparent color with respect to UIImageView to make more precise view on zoom in and zoom out in mapview.

code -----

Code-----

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString * const kPinAnnotationIdentifier = @"PinIdentifier";
    if(annotation == self._mapView.userLocation)
    {
        return nil;
    }

    MyAnnotation *myAnnotation  = (MyAnnotation *)annotation;
    MKAnnotationView *newAnnotation = (MKAnnotationView*)[self._mapView dequeueReusableAnnotationViewWithIdentifier:kPinAnnotationIdentifier];

    if(!newAnnotation){
        newAnnotation = [[MKAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:@"userloc"];
    }

    NSDictionary *dict=[alertInfoArray objectAtIndex:myAnnotation.ann_tag];
    UIView *anView=[[UIView alloc] init];
    anView.backgroundColor=[UIColor clearColor];

    UIImageView *bgImg=[[UIImageView alloc] init];
    bgImg.image=[UIImage imageNamed:@""];
    bgImg.backgroundColor=[UIColor clearColor];

    UIImageView *imgView=[[UIImageView alloc] init];
    imgView.tag=myAnnotation.ann_tag;

    UILabel *lblName=[[UILabel alloc] init];
    lblName.font=[UIFont systemFontOfSize:12];
    lblName.textAlignment=UITextAlignmentCenter;
    lblName.textColor=[UIColor whiteColor];
    lblName.backgroundColor=[UIColor clearColor];
    lblName.text=TEXT YOU WANT ;

    newAnnotation.frame=CGRectMake(0, 0, 70, 212);
    anView.frame=CGRectMake(0, 0, 70, 212);
    bgImg.frame=CGRectMake(0, 0, 70, 106);
    bgImg.image=[UIImage imageNamed:@"thumb-needhelp.png"];

    imgView.frame=CGRectMake(8,25,55,48);
    imgView.image=[UIImage imageNamed:@"girl-default.png"];
    lblName.frame=CGRectMake(5,79,60,10);



    [anView addSubview:bgImg];
    [bgImg release];
    [anView addSubview:imgView];
    [imgView release];
    [newAnnotation addSubview:anView];
    [anView release];

    newAnnotation.canShowCallout=YES;
    [newAnnotation setEnabled:YES];

    return newAnnotation;
}

希望这有助于。

这篇关于如何在图形页面与图像和标签在IPhone添加注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆