2014-09-21 75 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 

解决,但是当我使用这个解决方案的标注没有出现......