更改rightCalloutAccessoryView的颜色

时间:2015-09-14 13:09:58

标签: ios swift mkmapview

不知怎的,我的rightCalloutAccessoryView不可见,这就是它的样子:

enter image description here

按钮位于右侧,但它是白色的。我该如何改变它的颜色?据我所知,它通常是蓝色的。

这是我的代码:

func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
    if !(annotation is CustomPointAnnotation) {
        return nil
    }

    let reuseId = "test"

    var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
    if anView == nil {
        anView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        anView!.canShowCallout = true
        anView!.calloutOffset = CGPoint(x: -5, y: 5)
        anView!.rightCalloutAccessoryView = UIButton.buttonWithType(UIButtonType.InfoLight) as! UIView
    }
    else {
        anView!.annotation = annotation
    }

    //Set annotation-specific properties **AFTER**
    //the view is dequeued or created...

    let cpa = annotation as! CustomPointAnnotation
    anView!.image = UIImage(named:cpa.imageName)

    return anView
}

1 个答案:

答案 0 :(得分:0)

啊,我找到了答案。这就是我做到的。

var calloutButton = UIButton.buttonWithType(.DetailDisclosure) as! UIButton
calloutButton.setImage(UIImage(named: "arrow-right.png"), forState: UIControlState.Normal)
calloutButton.tintColor = UIColor(red: CGFloat(51/255.0), green: 51/255, blue: 51/255, alpha: 1)

我只需要调用按钮tintColor。