Ios XCode-在MKAnnotationView中将按钮设置为leftCalloutAccessoryView
我正在尝试将文本为“button”的按钮设置为左侧详图索引附件视图。这是我到目前为止所拥有的Ios XCode-在MKAnnotationView中将按钮设置为leftCalloutAccessoryView,ios,swift,mapkit,mapkitannotation,Ios,Swift,Mapkit,Mapkitannotation,我正在尝试将文本为“button”的按钮设置为左侧详图索引附件视图。这是我到目前为止所拥有的 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { if let annotation = annotation as? LocationObjects{ if let view = mapView.dequeueReusableAnnotat
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
}
之后会抛出一个错误
test.setTitle("Button", for: .normal)
但如果我删除该行并设置
let test = UIButton(type: .system)
到
如何将按钮设置为文本而不是图像或默认系统图标
谢谢
let test = UIButton(type: .detailDisclosure)