- (void)showLabelAnimation
{
[UIView beginAnimations:@"animationID" context:nil];
[UIView setAnimationDuration:1];
//original rectangle is (0,0,100,50)
//and I want to change label to (100,100,200,100)
label.bounds = CGRectMake(100, 100, 200, 100);
label.frame = CGRectMake(100, 100, 200, 100);
[UIView commitAnimations];
}
It works well, but I just wondering why I have to set both bounds and frame of label. They seem like the same thing.
Can anyone explains this for me?
Thanks in advance.
[Edit in Nov 3rd]
Thanks for your help, but when I remove the setbounds line, it doesn’t work well, the label will be large immediately but move to new position by animation. The resize animation does not show up.
That’s the real thing which wonder me.
You should only have to set the frame. Bounds should update on its own.
Edit for additional help:
Labels don’t scale; changing the frame of it changes where the text is placed, but the size of the text does not scale this way.
However, you can enable the UILabel’s
adjustsFontSizeToFitWidthproperty to ‘yes’ and then before you run the animation, set the font size to be at its largest before running it. As it scales, the font size should change to fit and achieve the effect you’re looking for.