ios - Set UILabel line spacing -
how can modify gap between lines in multiline uilabel
?
edit: evidently nsattributedstring
it, on ios 6 , later. instead of using nsstring
set label's text, create nsattributedstring
, set attributes on it, set .attributedtext
on label. code want this:
nsmutableattributedstring* attrstring = [[nsmutableattributedstring alloc] initwithstring:@"sample text"]; nsmutableparagraphstyle *style = [[nsmutableparagraphstyle alloc] init]; [style setlinespacing:24]; [attrstring addattribute:nsparagraphstyleattributename value:style range:nsmakerange(0, strlength)]; uilabel.attributedtext = attrstring;
nsattributedstring's old attributedstringwithstring did same thing, that being deprecated.
for historical reasons, here's original answer:
short answer: can't. change spacing between lines of text, have subclass uilabel
, roll own drawtextinrect
, create multiple labels, or use different font (perhaps 1 edited specific line height, see phillipe's answer).
long answer: in print , online world, space between lines of text known "leading" (rhymes 'heading', , comes lead metal used decades ago). leading read-only property of uifont
, deprecated in 4.0 , replaced lineheight
. far know, there's no way create font specific set of parameters such lineheight
; system fonts , custom font add, can't tweak them once installed.
there no spacing parameter in uilabel
, either.
i'm not particularly happy uilabel
's behavior is, suggest writing own subclass or using 3rd-party library. make behavior independent of font choice , reusable solution.
i wish there was more flexibility in uilabel
, , i'd happy proven wrong!
Comments
Post a Comment