2011-08-04 91 views
0

希望指定除默認紅色以外的地圖引腳的顏色。從文檔中,MKPinAnnotationView類有一個pinColor屬性,我們可以在其中設置顏色。我的問題是:什麼是將此pinColor屬性與註釋對象關聯的正確方法?有關MKPinAnnotationView的問題

希望有人見地這個可以幫助...

回答

0

我希望我理解你正確的質疑。 我想這將是你的邏輯的一部分,並沒有一個「正確」的答案。 在一個應用程序中,我可能會有一個plist,其中包含我應用程序中所有對象的定義及其屬性。在另一個更簡單的應用程序中,我可能只是在創建索引時根據索引指定顏色。

如果你只是想知道如何設置屬性然後按照上面

+0

已使用類似於「[mapView addAnnotation:mp_0];」的語句(其中mp_0是註釋對象)添加註釋。我的問題是如何將PinView對象(如@ Shrey的答案中的那些)與註釋對象相關聯。 – Stanley

+1

查看viewForAnnotation – ader

+0

viewForAnnotation似乎是我正在尋找的答案謝謝... – Stanley

2

我認爲只有三種顏色爲pinColor屬性定義Shrey的建議。

enum { 
    MKPinAnnotationColorRed = 0, 
    MKPinAnnotationColorGreen, 
    MKPinAnnotationColorPurple 
}; 
typedef NSUInteger MKPinAnnotationColor; 

下面是定義它的方法。

MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc] 
              initWithAnnotation:annotation reuseIdentifier:MyAnnotationIdentifier] autorelease]; 
      customPinView.pinColor = MKPinAnnotationColorPurple; 
+0

感謝您的示例代碼,它顯示瞭如何創建具有指定顏色的視圖對象。但是,我們如何將視圖對象與實際的註釋對象相關聯? – Stanley

+1

所有你的問題的答案,在於這個樣本夥伴.. http://developer.apple.com/library/ios/#samplecode/MapCallouts/Introduction/Intro.html – Hisenberg

+0

感謝您的鏈接到示例代碼和你的親切協助。 – Stanley