ios - How to set maximum length for UILabel? -


in objective-c, attempting set limit of character length uilabel, not find way anywhere. example, line of text entered uilabel, 100, if maximum character length set 50, want cut off @ 50 , not truncate. cut off once hits limit.

i have tried this; didn't work:

 nsstring *string = my_uilabeltext;   if ([string length] >74) {      string = [string substringtoindex:74];   }  

any insight or appreciated. thank you

based on comment, implemented work. have ensure syntax correct.

assuming getting string database:

nsstring *string = stringfromdatabase; //execute conditional if statement if (string.length > 50) { //meaning 51+     /* trim string. important note substringtoindex returns     new string containing characters of receiver to, not      including, 1 @ given index. in other words, goes 50,      not 50, means have desired number + 1.      additionally, method includes counting white-spaces */      string = [string substringtoindex:51]; } 

then must set labels text, doesn't happen autonomously. completely:

nsstring *string = stringfromdatabase; if (string.length > 50) {      string = [string substringtoindex:51]; } self.someuilabel.text = string; 

i think way doing not user friendly. you're getting string of uilabel has text set , resetting it. instead, should set desired text uilabel before called delegate


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -