uilabel - How to use NSLineBreakByCharWrapping with setNumberOfLines:1 on iOS? -
for example, if text uilabel is: "questions may have answer", want print "questions may alr". don't want clip last character cut text @ point.
i cannot use character limit fonts not monospaced. cannot use clipping may cut text @ point or may cut last letter "r" of it.
the behaviour want similar nslinebreakbycharwrapping while numberoflines = 0.
so, want drop(wrap) non-fitting last character want drop/wrap hidden space = don't want second line.
how can possible?
to required output need know width of label, can known following method:
cgsize size = [string sizewithattributes: @{nsfontattributename: [uifont systemfontofsize:17.0f]}]; // ios 7 , later cgsize size = [string sizewithfont: [uifont systemfontofsize:17.0f]]; // prior ios 7 - set size of label above calculated size.
- set numberoflines property 1;
set linebreakmode property nslinebreakbycharwrapping;
uilabel *yourlbl = [[uilabel alloc] initwithframe:cgrectmake(50, 50, size.width, 50)]; placelbl.numberoflines = 1; placelbl.linebreakmode = nslinebreakbycharwrapping;
Comments
Post a Comment