0

*Question is : How can i make the button (when pressed) open the link witch corresponds to the chosen shop on the pin?

I have an array of shops (for pins) (i created a class for it, and a class for pinAnnotation)

here i am creating button and pin image

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    let identifier = "annotationReusedId"
    var anView = myMapView.dequeueReusableAnnotationView(withIdentifier: identifier)

if anView == nil {

        anView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)

    } else {
        anView!.annotation = annotation
    }
    anView!.image = UIImage(named: "upcycled")
    anView?.frame = CGRect(x: 0, y: 0, width: 35, height: 35)
    anView!.backgroundColor = UIColor.clear
    anView!.canShowCallout = true
    let rightButton = UIButton(type: .infoLight)
    rightButton.tag = annotation.hash
    rightButton.addTarget(self, action:#selector(openLinkInstagram), for: .touchUpInside)

    //anView!.animatesDrop = true
    anView!.canShowCallout = true
    anView!.rightCalloutAccessoryView = rightButton
    return anView
}

here is func for openning link

func openLinkInstagram() {
}

  • chec kout this answer [How to create Custom MKAnnotationView and custom annotation title and subtitle](http://stackoverflow.com/questions/16252764/how-to-create-custom-mkannotationview-and-custom-annotation-title-and-subtitle) it should help to solve you problem – Ivan Besarab May 11 '17 at 14:09
  • Check out this answer [How to create Custom MKAnnotationView and custom annotation title and subtitle](http://stackoverflow.com/questions/16252764/how-to-create-custom-mkannotationview-and-custom-annotation-title-and-subtitle) should help. – Ivan Besarab May 11 '17 at 14:12

0 Answers0