fortunately, standard callout view mkannotationview
meets our needs - title
, subtitle
, leftcalloutaccessoryview
, , rightcalloutaccessoryview
.
unfortunately, use custom fonts in our app, , extend custom fonts these callouts.
mkannotationview provides no standard way accomplish this.
how can use custom font in mkannotation
's callout view?
since needed swift version - here is. also, have call setneedslayout() on didaddsubview() because otherwise when deselect , reselect annotation layoutsubviews() not called , callout has old font.
// elsewhere, in category on uiview. // answer: http://stackoverflow.com/a/25877372/607876 typealias viewblock = (view : uiview) -> bool extension uiview { func loopviewhierarchy(block : viewblock?) { if block?(view: self) ?? true { subview in subviews { subview.loopviewhierarchy(block) } } } } // then, in mkannotationview subclass class customfontannotationview : mkannotationview { override func didaddsubview(subview: uiview) { if selected { setneedslayout() } } override func layoutsubviews() { // mkannotationviews have subviews if they've been selected. // short-circuit if there's nothing loop on if !selected { return } loopviewhierarchy({(view : uiview) -> bool in if let label = view as? uilabel { label.font = labelfont return false } return true }) } }
Comments
Post a Comment