首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >更改颜色引脚iOS 9 Mapkit

更改颜色引脚iOS 9 Mapkit
EN

Stack Overflow用户
提问于 2015-09-28 03:39:31
回答 1查看 4.4K关注 0票数 2

我不知道如何更改iOS 9中引脚颜色的代码(因为苹果最近改变了它的代码),而且我在Swift中还是新手。因此,我现在不知道如何将pinTintColor集成到代码中。

请在下面找到我的代码:

代码语言:javascript
运行
复制
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.
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-28 03:46:33

pinColor在iOS 9中被废弃,使用pinTintColor代替。

示例:

代码语言:javascript
运行
复制
let annotationView = MKPinAnnotationView()
annotationView.pinTintColor = UIColor.purpleColor()

虽然OP专门要求使用iOS 9,但下面的操作可以确保在iOS 9之前的“非推荐”方法可以被调用:

代码语言:javascript
运行
复制
if #available(iOS 9, *) {
    annotationView.pinTintColor = UIColor.purpleColor()
} else {
    annotationView.pinColor = .Purple
}

如果您的最小目标是iOS 9(如您在这里特别要求的那样),那么上面的内容将是多余的- Xcode也会通过警告让您知道这一点,以了解您的信息。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32815367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档