创建具有不同颜色的注解?(Create Annotations with different col

2019-10-18 01:06发布

我只是用Xcode中开始开发,并想知道如果我能得到一些帮助。 我想在地图上显示的位置。 我有地图的工作和基本的注解了。 不过,我想对于加油站的注释是绿色的,例如。 也许在购物商场红色。 我发现了一个教程,但事实证明所有不同的颜色。 我怎么会去使只有某些注释红色和绿色的人? (如果你不介意它分解,我还在努力学习):)

谢谢!

这里是我的代码。 ViewController.h:

    #import <UIKit/UIKit.h>
    #import <MapKit/MapKit.h>

    @interface ViewController : UIViewController <MKMapViewDelegate>

    @property (nonatomic, strong) IBOutlet MKMapView *mapView;

    @end

ViewController.m:

      #import "ViewController.h"
      #import "Annotation.h"

       @interface ViewController ()

       @end

       @implementation ViewController

     - (void)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation  (MKPinAnnotationView *)view {
view.pinColor = MKPinAnnotationColorGreen;

       }

      - (void)viewDidLoad
     {
       [super viewDidLoad];
       //---------- Grocery Stores--------------



       //---------------Meijer Richmond,KY Annotation--------------
       //Annotation
       //Create a coordinate for use with the annotation
       CLLocationCoordinate2D meijerRichmondLocation;
       meijerRichmondLocation.latitude = 37.76486;
       meijerRichmondLocation.longitude = -84.29691;


       //Create annotation obj
       Annotation *meijerAnnotation = [Annotation alloc];
       meijerAnnotation.coordinate = meijerRichmondLocation;
       meijerAnnotation.title = @"Meijer Richmond";
       meijerAnnotation.subtitle = @" 2013 Lantern Ridge Dr.";

       [self.mapView addAnnotation:meijerAnnotation];
//-------------------------------------------------------

//---------------Meijer Reynold Road Lexington, KY Annotation--------------
//Annotation
//Create a coordinate for use with the annotation
CLLocationCoordinate2D meijerLex1Location;
meijerLex1Location.latitude = 37.995744;
meijerLex1Location.longitude = -84.531546;


//Create annotation obj
Annotation *meijerLex1Annotation = [Annotation alloc];
meijerLex1Annotation.coordinate = meijerLex1Location;
meijerLex1Annotation.title = @"Meijer on Reynolds Road";
meijerLex1Annotation.subtitle = @"351 Meijer Way Suite 100";

[self.mapView addAnnotation:meijerLex1Annotation];
//----------------------------------------------------------------------


//---------------Meijer Lexington, KY Annotation-------------------------------
MKPointAnnotation *meijerLex2Annotation = [[MKPointAnnotation alloc] init];
meijerLex2Annotation.title = @"Meijer on Man-O-War";
meijerLex2Annotation.subtitle = @"2155 Paul Jones Way";
meijerLex2Annotation.coordinate = CLLocationCoordinate2DMake(38.0208932,-84.420606);
[self.mapView addAnnotation:meijerLex2Annotation];





//------------ Malls ----------------



//-------------------Mall Annotation---------------------
//Mall Annotation
//Create a coordinate for use with the annotation
CLLocationCoordinate2D fayetteMallLocation;
fayetteMallLocation.latitude = 37.9909;
fayetteMallLocation.longitude = -84.5269;


//Create annotation obj
Annotation *fayetteMallAnnotation = [Annotation alloc];
fayetteMallAnnotation.coordinate = fayetteMallLocation;
fayetteMallAnnotation.title = @"Fayette Mall";
fayetteMallAnnotation.subtitle = @"Lexington's Main Shopping Center.";

//-------------------------------------------------------



[self.mapView addAnnotation:fayetteMallAnnotation];


self.mapView.delegate = self;
// Do any additional setup after loading the view, typically from a nib.
    }

     - (void)didReceiveMemoryWarning
     {
     [super didReceiveMemoryWarning];
     // Dispose of any resources that can be recreated.
     }

   @end
文章来源: Create Annotations with different colors?