gpt4 book ai didi

ios - 更改图像图钉图

转载 作者:行者123 更新时间:2023-11-29 10:24:23 24 4
gpt4 key购买 nike

我应该写什么来放置个人照片而不是传统的红色别针?

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

if annotation is MKUserLocation {
return nil
}

let annView : MKPinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "currentloc")
annView.pinTintColor = UIColor.redColor()
annView.animatesDrop = true
annView.canShowCallout = true
annView.calloutOffset = CGPointMake(-8, 0)

annView.autoresizesSubviews = true
annView.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure) as UIView

return annView
}

最佳答案

使用MKAnnotationView代替MKPinAnnotationView,然后设置它的image属性。我还建议实现出队逻辑,以便可以重用注释:

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}

let annotationIdentifier = "SomeCustomIdentifier" // use something unique that functionally identifies the type of pin

var annotationView: MKAnnotationView! = mapView.dequeueReusableAnnotationViewWithIdentifier(annotationIdentifier)

if annotationView != nil {
annotationView.annotation = annotation
} else {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)

annotationView.image = UIImage(named: "annotation.png")

annotationView.canShowCallout = true
annotationView.calloutOffset = CGPointMake(-8, 0)

annotationView.autoresizesSubviews = true
annotationView.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure) as UIView
}

return annotationView
}

关于ios - 更改图像图钉图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33189595/

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