Size image pin annotation

前端 未结 2 1088
梦如初夏
梦如初夏 2021-02-04 11:05

I put the personal image instead of the traditional red pin. When I open the map to display the pin, the image cover the entire map. Is there a maximum size of the pin image or

2条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 11:25

    There is not a maximum size of the pin image. You need to resize UIImage.

        let annotationIdentifier = "SomeCustomIdentifier"
        var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier)
        if annotationView == nil {
            annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
            annotationView?.canShowCallout = true
    
            // Resize image
            let pinImage = UIImage(named: "pin maps.png")
            let size = CGSize(width: 50, height: 50)
            UIGraphicsBeginImageContext(size)
            pinImage!.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
            let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
    
            annotationView?.image = resizedImage
    
            let rightButton: AnyObject! = UIButton(type: UIButtonType.detailDisclosure)
            annotationView?.rightCalloutAccessoryView = rightButton as? UIView
        }
        else {
            annotationView?.annotation = annotation
        }
    

提交回复
热议问题