I have the problem, that my Aotation is still a pin! I want the Button and the picture, for the information displayed about the User and it works. But it doesn't change the look of the pin on the Map! This is my aotationView:
func mapView(mapView: MKMapView, viewForAotation aotation: MKAotation) -> MKAotationView? {
// 1
let identifier = "pinAotation"
// 2
if aotation.isKindOfClass(pinAotation.self) {
// 3
var aotationView = mapView.dequeueReusableAotationViewWithIdentifier(identifier)
if aotationView == nil {
//4
aotationView = MKPinAotationView(aotation: aotation, reuseIdentifier: identifier)
aotationView!.canShowCallout = true
// 5
let btn = UIButton(type: .InfoDark)
aotationView!.rightCalloutAccessoryView = btn
resultImgArray[0].getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
let imageView = UIImageView(frame:CGRectMake(0,0,45,45))
imageView.image = UIImage(data: imageData!)
aotationView!.leftCalloutAccessoryView = imageView
}
}
} else {
// 6
aotationView!.aotation = aotation
}
retu aotationView
}
retu nil
}
This is my pinAotationView.swift as MKAotationView: `
import UIKit import MapKit import CoreLocation
class pinAotationView: MKAotationView {
override init(frame :CGRect) {
super.init(frame: frame)
}
override init(aotation: MKAotation?, reuseIdentifier: String?) {
super.init(aotation: aotation, reuseIdentifier: reuseIdentifier)
var frame = self.frame
frame.size = CGSizeMake(80, 80)
self.frame = frame
self.backgroundColor = UIColor.clearColor()
self.centerOffset = CGPointMake(-5, -5)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
UIImage(named: "carlogo.png")?.drawInRect(CGRectMake(30, 30, 30, 30))
}
} `
