更改颜色pin iOS 9 Mapkit
我不知道如何改变在iOS 9的针颜色的代码(因为最近苹果改变了它的代码),我还是在Swift新。 所以,我不知道如何将pinTintColor
集成到我的代码中。
请在下面find我的代码:
import UIKit import MapKit class ViewController: UIViewController, MKMapViewDelegate { @IBOutlet var map: MKMapView! override func viewDidLoad() { super.viewDidLoad() let annotation = MKPointAnnotation() let latitude:CLLocationDegrees = 40.5 let longitude:CLLocationDegrees = -74.6 let latDelta:CLLocationDegrees = 150 let lonDelta:CLLocationDegrees = 150 let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta) let location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude) let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span) map.setRegion(region, animated: false) annotation.coordinate = location annotation.title = "Niagara Falls" annotation.subtitle = "One day bla bla" map.addAnnotation(annotation) } func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { // simple and inefficient example let annotationView = MKPinAnnotationView() annotationView.pinColor = .Purple return annotationView } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
pinColor
在iOS 9中已弃用,请改用pinTintColor
。
例:
let annotationView = MKPinAnnotationView() annotationView.pinTintColor = UIColor.purpleColor()
尽pipeOP特别要求iOS 9,但以下内容可以确保可以调用iOS 9之前的“不推荐”方法:
if #available(iOS 9, *) { annotationView.pinTintColor = UIColor.purpleColor() } else { annotationView.pinColor = .Purple }
如果你的最小目标是iOS 9,就像你在这里特别提出的那样,那么上面的内容就会是多余的–Xcode会让你知道,同时也有一个警告信息。
- 如何辨别智能反转在iOS 11不反转我的应用程序的颜色,并检测是否启用?
- 原生应用程序如何脱离“响应”?
- 解除模块的模态视图时,Dealloc不运行
- 在Swift 2.0中更改AVAudioPlayer的rate var时发生声音失真
- MFMailComposeViewController栏的背景颜色在iOS7中不变
- iOS – 使用UIPageContol加载和切换页面
- TableView无法使用AFNetworking响应对象中的新数据重新加载
- 在Windows中制作CSR证书(7)
- React Native IOS 11.3 – 11.4错误:JavaScriptCore JSC :: JSLock :: DropAllLocks :: DropAllLocks