I have the following code:
desc = [[UILabel alloc] initWithFrame:CGRectMake(134, 5, 185, 60)];
[desc setNumberOfLines:20];
[dataView addSubview:desc];
desc.text =@"1111\n2222\n3333\n4444\n5555\n6666\n7777\n8888" ;
the data is not fitting in the label so I see something like:
1111
2222
3333
4444…
I also a button that when you click it i want to expand the label so all the data is visible. For that I have the following code:
CGSize newDescSize = [desc.text sizeWithFont:[UIFont italicSystemFontOfSize:12] constrainedToSize:CGSizeMake(185, 400)];
[UIView beginAnimations:@"expandDesc" context:nil];
[UIView setAnimationDuration:1.0];
CGRect frame = desc.frame;
frame.size.height=newDescSize.height;
desc.frame=frame;
[UIView commitAnimations];
It works fine except that the animation starts from the view:
3333
4444
5555
6666
and while expanding both lines are added on the bottom and the top, so the animation is not smooth, I want the the text will expand from the original text and lines will be added at the bottom.
does anyone know what i’m doing wrong?
Nothing is wrong. The
-drawRect:method of the UILabel is optimized so that It doesn’t draw outside its bounds. This, simply put, means that you won’t have a smooth transition for it, it will jerk from both ends. Without using a custom class, I don’t know what you can do.