XCode - 在MKAnnotationView中将按钮设置为leftCalloutAccessoryView

时间:2017-05-25 19:45:40

标签: ios swift mapkit mapkitannotation

我正在尝试设置一个按钮,文本“按钮”作为左侧标注附件视图。这是我到目前为止所拥有的

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)

如何将按钮设置为文本而不是图像或默认系统图标?

谢谢!

0 个答案:

没有答案