hope you are doing good.
I am setting a label and adjusting its frame ..
UILabel *mylabel=[[UILabel alloc]init];
mylabel.Text=@"This is my label";
mylabel.frame=CGRectMake(10,10,200,21);
now if I change the Label’s text from any string set by me like this
NSString *mystring=@"This is my first string that is to be assigned to my label dynamilcally";
mylabel.Text=mystring;
mylabel.frame.size.width=mystring.length;
but nothing happens. The width of the label remains 200, as I set while at the time of initialisation.
This will also need to get the width of the mystring . How to get that?
Thank in anticipation for helping me a lot.
[myLabel sizeToFit]if you need it on one line. For multiple line labels you can useNSString‘ssizeWithFont:constrainedToSize:lineBreakMode:function to get size of your string and use it to modify your label’s height & width.e.g. code that gives you height for multiline label with fixed width of 200px: