gpt4 book ai didi

ios - 更改颜色图钉 iOS 9 Mapkit

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:06:17 26 4
gpt4 key购买 nike

我不知道如何在 iOS 9 中更改图钉颜色的代码(因为最近 Apple 更改了它的代码),而且我对 Swift 还是个新手。所以,我现在不知道如何在我的代码中集成 pinTintColor

请在下面找到我的代码:

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()

尽管 OP 特别要求 iOS 9,但以下内容可以确保可以调用 iOS 9 之前的“非弃用”方法:

if #available(iOS 9, *) {
annotationView.pinTintColor = UIColor.purpleColor()
} else {
annotationView.pinColor = .Purple
}

如果您的最低目标是 iOS 9,正如您在此处特别询问的那样,那么以上内容将是多余的 - Xcode 也会通过警告让您知道这一点,以供您引用。

关于ios - 更改颜色图钉 iOS 9 Mapkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32815367/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com