mapkit - Creating a dynamic MKAnnotationView in Swift -
currently, know how create mkannotationview static pin, image that's added.
does know, or have resources, on how create pin change colors or have number displayed inside of change depending on information business?
for instance, have pin red when business closed, , green when business open. maybe dollar signs inside of pin tell user how expensive is.
edit
i have created class called custompin
adopts mkannotation
protocol. additionally, i'm not looking have custom mkannotationview
image can change. mean i'll have add multiple images mkannotationview
in array , have change image everytime details business change?
thank in advance!
you can create custom mkannotationview
inheritance. can use class create annotation view delegate method.
here 1 example.
class kdannotationview: mkannotationview { let titlelabel = uilabel() convenience init(annotation: mkannotation?) { self.init(annotation: annotation, reuseidentifier: "indetifier") self.canshowcallout = false self.frame = cgrectmake(0, 0, 75.0, 85.0) self.backgroundcolor = uicolor.clearcolor() self.centeroffset = cgpointmake(0, 0) self.titlelabel.backgroundcolor = uicolor.clearcolor() self.titlelabel.textcolor = uicolor.blackcolor() self.titlelabel.font = uifont.systemfontofsize(16.0) self.addsubview(self.titlelabel) } override func layoutsubviews() { super.layoutsubviews() var frame = cgrectinset(self.bounds, 5.0, 5.0) frame.size.height = 20.0 self.titlelabel.frame = frame } override func drawrect(rect: cgrect) { super.drawrect(rect) let path = uibezierpath() path.movetopoint(cgpoint(x: cgrectgetminx(rect), y: cgrectgetminy(rect))) path.addlinetopoint(cgpoint(x: cgrectgetmaxx(rect), y: cgrectgetminy(rect))) path.addlinetopoint(cgpoint(x: cgrectgetmaxx(rect), y: cgrectgetmaxy(rect) - 10.0)) path.addlinetopoint(cgpoint(x: cgrectgetmidx(rect) + 5.0, y: cgrectgetmaxy(rect) - 10.0)) path.addlinetopoint(cgpoint(x: cgrectgetmidx(rect), y: cgrectgetmaxy(rect))) path.addlinetopoint(cgpoint(x: cgrectgetmidx(rect) - 5.0, y: cgrectgetmaxy(rect) - 10.0)) path.addlinetopoint(cgpoint(x: cgrectgetminx(rect), y: cgrectgetmaxy(rect) - 10.0)) path.closepath() uicolor.lightgraycolor().setstroke() uicolor.whitecolor().setfill() path.stroke() path.fill() } //mark: - public methods func settext(text:string) { self.titlelabel.text = text } }
Comments
Post a Comment