Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grant-park/7768ca571bcb7150c8a3 to your computer and use it in GitHub Desktop.
Save grant-park/7768ca571bcb7150c8a3 to your computer and use it in GitHub Desktop.
extension MapViewController: MKMapViewDelegate {
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if let annotation = annotation as? Food {
if annotation == mapView.userLocation {
return nil
}
let identifier = "pin"
var view: CustomPin
if let dequeuedView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) as? CustomPin
{
dequeuedView.annotation = annotation
view = dequeuedView
} else {
view = CustomPin(annotation: annotation, reuseIdentifier: identifier)
view.image = annotation.image
}
return view
}
return nil
}
}
------------------------------------------------------------------------------------------------------------------------------
import UIKit
import MapKit
class CustomPin: MKAnnotationView {
override init(annotation:MKAnnotation, reuseIdentifier:String) {
super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)
self.canShowCallout = true
self.opaque = false
}
override init(frame: CGRect) {
super.init(frame:frame)
}
required init(coder: NSCoder) {
fatalError("NSCoding not supported")
}
override func drawRect(rect: CGRect)
{
println("Please please please work")
var startAngle: Float = Float(2 * M_PI)
var endAngle: Float = 0.0
let strokeWidth = 1.0
let radius = CGFloat((CGFloat(self.frame.size.width) - CGFloat(strokeWidth)) / 2)
var context = UIGraphicsGetCurrentContext()
let center = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2)
CGContextSetStrokeColorWithColor(context, UIColor.whiteColor().CGColor)
CGContextSetLineWidth(context, CGFloat(strokeWidth))
CGContextSetFillColorWithColor(context, UIColor.clearColor().CGColor)
startAngle = startAngle - Float(M_PI_2)
endAngle = endAngle - Float(M_PI_2)
CGContextAddArc(context, center.x, center.y, CGFloat(radius), CGFloat(startAngle), CGFloat(endAngle), 0)
CGContextDrawPath(context, kCGPathStroke)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment