ios - 更改 rightCalloutAccessoryView 的颜色

标签 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
}

最佳答案

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

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”即可。

关于ios - 更改 rightCalloutAccessoryView 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32565713/

相关文章:

ios - CoreData 有序关系 - 使用 NSFetchRequest 进行批处理

json - 如何在 swift 中使用 utf-8 解码 json 文件 3/4

ios - 锁定然后解锁代码一段时间

iphone - 我如何检查 NSNumber 是否为空?

ios - AVAssetWriterInputPixelBufferAdaptor appendPixelBuffer :buffer withPresentationTime returning error NSURLErrorCannotCreateFile

ios - 出现 View 时在表中加载新数据

iphone - iOS 6 - 我可以在解除 segue 时返回数据吗?

ios - 'NSString !' is not convertible to ' 字符串';您的意思是使用 'as!' 强制向下转换吗?

swift - 在 Swift 中返回结构的可变版本

ios - 将搜索字符串从 UISearchBar 转换为 MK MapView 地址