如何更改 Mapbox 上 rightCalloutAccessory 的色调颜色?
How to change tint color of a rightCalloutAccessory on Mapbox?
有没有办法改变注释 rightCalloutAccessory
的色调,而不改变 mapView
的色调?
例如,我想将地图色调设置为白色,以便右下角的用户当前位置和信息图标为白色,但我希望注释 calloutAccessory
是蓝色的。
我想你想更改注释视图的色调。您可以通过调用 MKMapViewDelegate
协议的函数来完成此操作:
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier("annotationView") as? MKPinAnnotationView
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "annotationView")
}
annotationView?.canShowCallout = true
annotationView?.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure)
annotationView?.rightCalloutAccessoryView?.tintColor = UIColor.whiteColor()
return annotationView
}
你需要 mapView:rightCalloutAccessoryViewForAnnotation:
,可以这样使用:
- (UIView *)mapView:(__unused MGLMapView *)mapView rightCalloutAccessoryViewForAnnotation:(__unused id<MGLAnnotation>)annotation
{
UIButton *rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeInfoLight];
rightCalloutAccessoryView.tintColor = [UIColor blueColor];
return rightCalloutAccessoryView;
}
有没有办法改变注释 rightCalloutAccessory
的色调,而不改变 mapView
的色调?
例如,我想将地图色调设置为白色,以便右下角的用户当前位置和信息图标为白色,但我希望注释 calloutAccessory
是蓝色的。
我想你想更改注释视图的色调。您可以通过调用 MKMapViewDelegate
协议的函数来完成此操作:
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier("annotationView") as? MKPinAnnotationView
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "annotationView")
}
annotationView?.canShowCallout = true
annotationView?.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure)
annotationView?.rightCalloutAccessoryView?.tintColor = UIColor.whiteColor()
return annotationView
}
你需要 mapView:rightCalloutAccessoryViewForAnnotation:
,可以这样使用:
- (UIView *)mapView:(__unused MGLMapView *)mapView rightCalloutAccessoryViewForAnnotation:(__unused id<MGLAnnotation>)annotation
{
UIButton *rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeInfoLight];
rightCalloutAccessoryView.tintColor = [UIColor blueColor];
return rightCalloutAccessoryView;
}