ios - Coloring links with multiple various colors in the same NSAttributedString -
i'm using tttattributedlabel detect clicks on links in styled uilabel
(using nsattributedstring
), in ios 6 project. i'd able have alternating colors links in label; i'm fine manually setting different colors different link ranges, long library handles link-detection user touches me. seems tttattributedlabel
class applies link styling last, text styling specific ranges overwritten single link style set class instance.
being dive in , try modify tttattributedlabel
code (to either not apply link styling, or apply own style ranges afterwards), figured i'd ask here whether has better ideas consider achieving this. might different library support variously-colored link ranges in same label, out of box?
this supported, use:
- (void)addlinkwithtextcheckingresult:(nstextcheckingresult *)result attributes:(nsdictionary *)attributes;
this lets specify own attributes on per-link basis. e.g., linkattributes
dictionary one-off coloring of link:
if (linkattributes) { [self addlinkwithtextcheckingresult:[nstextcheckingresult linkcheckingresultwithrange:linkrange url:[nsurl urlwithstring:linktext]] attributes:linkattributes]; } else { [self addlinktourl:[nsurl urlwithstring:linktext] withrange:linkrange]; }
the link attributes dictionary uses keys defined in nsattributedstring.h
. example:
linkattributes = @{ nsforegroundcolorattributename: [uicolor greencolor], nsunderlinestyleattributename: @(nsunderlinestylenone) };
Comments
Post a Comment