ios - 将 PinTintColor 调整为 mapkit 的 Ray Wenderlich 教程

标签 ios swift xcode mapkit

我正在使用教程来构建我的第一个应用程序。 http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial

我搜索了 pintintcolor 但没有搜索到。

基本上教程使用这段代码来设置颜色

// pinColor for disciplines: Sculpture, Plaque, Mural, Monument, other
func pinColor() -> MKPinAnnotationColor{
    switch discipline {
    case "Sculpture", "Plaque":
        return .Red
    case "Mural", "Monument":
        return .Purple
    default:
        return .Green

问题是苹果在开发者网站上有什么

https://developer.apple.com/library/mac/releasenotes/General/APIDiffsMacOSX10_11/Swift/MapKit.html

修改后的 MKPinAnnotationView 声明

来自:

class MKPinAnnotationView : MKAnnotationView {
    var pinColor: MKPinAnnotationColor
    var animatesDrop: Bool
}

收件人:

class MKPinAnnotationView : MKAnnotationView {
    class func redPinColor() -> NSColor
    class func greenPinColor() -> NSColor
    class func purplePinColor() -> NSColor
    var pinTintColor: NSColor!
    var animatesDrop: Bool
    var pinColor: MKPinAnnotationColor
}

Ray Wenderlich 教程的设置有点不同,所以我不太了解如何按照相同的方式进行设置。我尝试了几种不同的配置,但无法正常工作。

感谢任何帮助

干杯

最佳答案

万一其他人正在学习教程并看到以下错误:“‘MKPinAnnotationColor’在 iOS 9.0 中已弃用:改用 MKPinAnnotationView 的 pinTintColor”

只需更新 pinColor 例程以返回 UIColor。

func pinColor() -> UIColor  {
    switch discipline {
    case "Sculpture", "Plaque":
        return UIColor.redColor()
    case "Mural", "Monument":
        return UIColor.purpleColor()
    default:
        return UIColor.greenColor()
    }
}

然后进行相应的调用以像这样设置 pinTintColor:

  view.pinTintColor = annotation.pinColor()

关于ios - 将 PinTintColor 调整为 mapkit 的 Ray Wenderlich 教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32692805/

相关文章:

ios - 阻止我的应用程序在当前发布的设备以外的设备上运行

ios - 模仿 UITextField 占位符颜色的正确方法

ios - 我可以使用 MetalKit 在 GPU 上编码和解码 JSON 吗?

ios - 重新加载具有图像的 UICollectionViewCell

ios - 将 UIButton 移动到键盘上方

xcode - 使用 NSTask 的 Swift 2.1 OSx shell 命令在从 xcode 运行时有效,但在导出时无效

ios - "Could not build module ' map 套件 '"

ios - 如何将标签从一个 UITableView 添加到另一个 UITableView

ios - 应用程序加载器显示旧图标

objective-c - Xcode 7 中的 DDHotKey