Skip to content

Instantly share code, notes, and snippets.

@ivangodfather
Created July 10, 2015 16:47
Show Gist options
  • Select an option

  • Save ivangodfather/746fdb5bf82072781f92 to your computer and use it in GitHub Desktop.

Select an option

Save ivangodfather/746fdb5bf82072781f92 to your computer and use it in GitHub Desktop.
func annotationView() -> MKAnnotationView {
let annonView = MKAnnotationView(annotation: self, reuseIdentifier: "annotation")
annonView.enabled = true
annonView.canShowCallout = true
let image = UIImage(named: "incident")
let imageView = UIImageView(frame: CGRectMake(0, 0, image!.size.width, image!.size.height))
imageView.image = image?.imageWithRenderingMode(.AlwaysTemplate)
let level = Model.getLevelWithId(incident.levelId)
var color = (level?.color != nil) ? level?.color : UIColor.redColor()
imageView.tintColor = color
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, 0.0)
imageView.layer.renderInContext(UIGraphicsGetCurrentContext())
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
annonView.image = img
annonView.tintColor = color
let rightButton = UIButton.buttonWithType(UIButtonType.InfoDark) as! UIButton
annonView.rightCalloutAccessoryView = rightButton
if_let(incident.user, incident.user?.avatar) { (user, avatarURL) -> () in
dispatch_async(dispatch_queue_create("imgDownload", nil), { () -> Void in
let data = NSData(contentsOfURL: avatarURL)
if let data = data {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let leftImageView = UIImageView(image: UIImage(data: data))
leftImageView.frame = CGRectMake(5, 0, 50, 50)
leftImageView.contentMode = UIViewContentMode.ScaleAspectFit
leftImageView.layer.cornerRadius = 25
leftImageView.clipsToBounds = true
annonView.leftCalloutAccessoryView = leftImageView
})
}
})
}
return annonView
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment