2015-11-06 3 views
0

je dois faire MKPinAnnotationView avec UIButton sur le côté gauche avec une image comme ceci: enter image description hereUIButton intérieur MKPinAnnotationView avec l'image

je tente d'écrire ce code, mais il est pas du travail:

let navBtn = UIButton(type: .Custom) 
    navBtn.setImage(UIImage(named: "TakeMe.png"), forState: .Selected) 
    navBtn.tag = artwork.id 
    navBtn.addTarget(self, action: "wazeNav:" , forControlEvents: UIControlEvents.TouchUpInside) 

    pinView?.rightCalloutAccessoryView = btn 
    pinView?.leftCalloutAccessoryView = navBtn 

plz Aidez-moi comment je peux faire ça?

+0

Recevez-vous des erreurs? – vinbhai4u

+0

Non, vous ne voyez pas le bouton – Tzahi

+0

Appellez-vous ceci dans viewForAnnoation? – vinbhai4u

Répondre

0

S'il vous plaît consulter le code ci-dessous

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView! { 

    let annotationView = AttractionAnnotationView(annotation: annotation, reuseIdentifier: "Attraction") 

    let button : UIButton = UIButton(type: UIButtonType.InfoDark) 

    button.frame = CGRect(x: 0, y: 0, width: 50, height: 50) 
    button.addTarget(self, action: "funcRightAcessoryButton:", forControlEvents: UIControlEvents.TouchUpInside) 
    annotationView.rightCalloutAccessoryView = button 
    annotationView.canShowCallout = true 

    let image = UIImage(named: "left_icon") 
    let buttonLeft : UIButton = UIButton(type: UIButtonType.Custom) 
    buttonLeft.setImage(image, forState: UIControlState.Normal) 

    buttonLeft.frame = CGRect(x: 0, y: 0, width: 60, height: 60) 
    buttonLeft.addTarget(self, action: "funcLeftAcessoryButton:", forControlEvents: UIControlEvents.TouchUpInside) 

    annotationView.leftCalloutAccessoryView = buttonLeft 

    return annotationView 
} 

it helps

+1

Tanks Workkkkkkk vous êtes le roi! – Tzahi