ios - TTTAttributedLabel links are being styled but not clickable -
i've been looking solution getting clickable links working. can working when using uitextview + nsattributedstring doesn't autolayout when it's uitableviewcell.
now i've added tttattributedlabel project , styles views perfectly. links turn blue , underlined.
however clicking them nothing. did implement tttattributedlabeldelegate on controller, made label in storyboard implement mylabel (which extends tttattributedlabel , has delegate options since want them fire inside same function). i've set controller delegate thinking might not work pointing itself.
but none of these functions fired, got breakpoints , logs in it.
i implemented didselectlinkwithurl , didlongpresslinkwithurl.
func attributedlabel(label: tttattributedlabel!, didselectlinkwithurl url: nsurl!) { debug.log("link clicked") } func attributedlabel(label: tttattributedlabel!, didlongpresslinkwithurl url: nsurl!, atpoint point: cgpoint) { debug.log("link long clicked") }
outlet
@iboutlet weak var content: mylabel!
mylabel
import uikit import tttattributedlabel
class mylabel : tttattributedlabel, tttattributedlabeldelegate { override func didmovetosuperview() { if (self.delegate == nil) { self.delegate = self } self.enabledtextcheckingtypes = nstextcheckingtype.link.rawvalue self.userinteractionenabled = true } func attributedlabel(label: tttattributedlabel!, didselectlinkwithurl url: nsurl!) { debug.log("link clicked") } func attributedlabel(label: tttattributedlabel!, didlongpresslinkwithurl url: nsurl!, atpoint point: cgpoint) { debug.log("link long clicked") }
anyone know missing?
update
i found out pasting in url f/e http://example.com becomes active , clickable , didselectlinkwithurl becomes clickable, allthough need attributed string , it's based on html string.
the implementation of setattributedtext:
doesn't update linkmodels
array, while the implementation of settext:
does. believe causes issue.
to resolve, set label's text
property instead of attributedtext
property.
the docs include warning:
tttattributedlabel
can display both plain , attributed text: passnsstring
ornsattributedstring
settext:
setter. never assignattributedtext
property.
the docs show example usage:
tttattributedlabel *attributedlabel = [[tttattributedlabel alloc] initwithframe:cgrectzero]; nsattributedstring *attstring = [[nsattributedstring alloc] initwithstring:@"tom bombadil" attributes:@{ (id)kctforegroundcolorattributename : (id)[uicolor redcolor].cgcolor, nsfontattributename : [uifont boldsystemfontofsize:16], nskernattributename : [nsnull null], (id)ktttbackgroundfillcolorattributename : (id)[uicolor greencolor].cgcolor }]; // attributed string directly set, without inheriting other text // properties of label. attributedlabel.text = attstring;
Comments
Post a Comment