iphone - How to highlight only text in UILabel - IOS -


i want highlight text in uilabel, have tried giving backgroundcolor label, highlighting empty spaces looks not good. there way highlight text without resizing uilabel.

please check image, here labels bigger text (center aligned)

enter image description here

thanx.

most of other solutions don't consider text spans multiple lines while still highlighting text, , pretty hacky involving subviews.

an ios 6 , later solution use attributed strings:

nsmutableattributedstring *s =      [[nsmutableattributedstring alloc] initwithstring:yourstring];  [s addattribute:nsbackgroundcolorattributename           value:[uicolor greencolor]           range:nsmakerange(0, s.length)];  label.attributedtext = s; 

Comments