I'm attempting to set a button with the text "Button" as the left callout accessory view. Here is what I have so far
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let annotation = annotation as? LocationObjects{
if let view = mapView.dequeueReusableAnnotationView(withIdentifier: annotation.identifier){
return view
}else{
let view = MKAnnotationView(annotation: annotation, reuseIdentifier: annotation.identifier)
view.isEnabled = true
view.canShowCallout = true
view.image = annotationPin
let test = UIButton(type: .system)
test.setTitle("Button", for: .normal)
view.leftCalloutAccessoryView = test
return view
}
}
return nil
}
It throws an error after
test.setTitle("Button", for: .normal)
But will not throw an error if I remove that line and set
let test = UIButton(type: .system)
to
let test = UIButton(type: .detailDisclosure)
How can I set the button to have text instead of an image or default system icon?
Thanks!