2014-09-21 74 views
2

我overrided MKAnnotationView到在地圖上顯示自定義圖像:MKAnnotationView圓形

override init(annotation: MKAnnotation!, reuseIdentifier: String!) { 
     super.init(annotation: annotation, reuseIdentifier: reuseIdentifier) 

     let img = UIImage(named: "annotation") 
     self.image = img 
     self.frame = CGRectMake(0, 0, 40, 40) 
     self.layer.cornerRadius = 20 
     self.contentMode = UIViewContentMode.ScaleAspectFit 
     self.centerOffset = CGPointMake(0, -20) 
    } 

我的目標是在地圖上創建一個圓形圖像,但cornerRadius不工作。

有人cal幫助我嗎?

謝謝。

+0

嘗試'self.layer.masksToBounds = TRUE'。 – Anna 2014-09-23 02:34:15

+0

不起作用:( – Kobazzo 2014-09-23 18:59:00

回答

0

您正在使用MKAnnotation這是一個數據模型。你想看看MKAnnotationView和相關的類爲你的註釋的視覺部分。檢查MapKit文檔。

+0

謝謝你的回答。但我重寫MKAnnotationView,事實上self.image被稱爲MKAnnotationView。我需要從UIImage(self.image)檢索UIImageView,但我不知道如何我能行 – Kobazzo 2014-09-22 21:57:33

1

我已經與

annotationView.layer.cornerRadius = 20 
    annotationView.layer.masksToBounds = true 

解決,但是當我使用這個解決方案的標註沒有出現......