我正在尝试设置一个按钮,文本“按钮”作为左侧标注附件视图。这是我到目前为止所拥有的
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)
如何将按钮设置为文本而不是图像或默认系统图标?
谢谢!