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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -