Swift 4在地图上绘制圆形图像

Swift 4在地图上绘制圆形图像,swift,label,rounding,mkannotation,Swift,Label,Rounding,Mkannotation,我想在地图上画一个圆形的图像。图像大小为200*200px,但变换后我的拐角半径有问题。有人能帮我吗 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { let annoView = MKAnnotationView(annotation: selectedAnnotation, reuseIdentifier: "") if (annota

我想在地图上画一个圆形的图像。图像大小为200*200px,但变换后我的拐角半径有问题。有人能帮我吗

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    let annoView = MKAnnotationView(annotation: selectedAnnotation, reuseIdentifier: "")

    if (annotation is MKUserLocation){
        return nil
    }
    if(annotation.title! == "Hej"){
        annoView.image = UIImage(named: "Hej")
        let transform = CGAffineTransform(scaleX: 0.3, y: 0.3)
        annoView.transform = transform
        annoView.layer.cornerRadius = 100
        annoView.layer.masksToBounds = true
        let label = UILabel(frame: CGRect(x: annoView.frame.size.width/2, y: annoView.frame.size.height/2, width: 200,height: 30))
        label.textColor = #colorLiteral(red: 0.7215686275, green: 0.8862745098, blue: 0.5921568627, alpha: 1)
        label.font = UIFont.boldSystemFont(ofSize: 30)
        label.center = CGPoint(x: 100, y: 0)
        label.textAlignment = .center
        label.text = "Hej"
        annoView.addSubview(label)    
    }
}

您甚至没有从函数返回
annoView
,那么您如何知道
corneradius
有问题?此外,您应该指定什么是错误的,“某物是错误的”不会使您的问题成为主题。请尝试设置
annoView.clipsToBounds=true
我将返回它,但是我忘了在这里添加它。问题是,我使用cornerRadius后,我的图像不是圆形的,它对annoView.clipsToBounds=true没有帮助。@Davidurand我测试了你的代码这是输出我不知道你的问题在哪里,但你必须检查图像的大小,并且更喜欢更改它的大小