How to increase dynamically UILabel (label and font size)?

I am currently working on an iPhone project. I want to dynamically increase UILabel in Objective-C as follows:

alt text http://img268.imageshack.us/img268/9683/bildschirmfoto20100323u.png

How is this possible? I thought I should do this with CoreAnimation, but I did not work. Here is the code I tried:

UILabel * fooL = //[…] fooL.frame = CGRectMake(fooL.frame.origin.x, fooL.frame.origin.y, fooL.frame.size.width, fooL.frame.size.height); fooL.font = [UIFont fontWithName:@"Helvetica" size:80]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; [UIView setAnimationDelegate:self]; [UIView setAnimationDuration:0.5]; [UIView setAnimationBeginsFromCurrentState:YES]; fooL.font = [UIFont fontWithName:@"Helvetica" size:144]; //bigger size fooL.frame = CGRectMake(20 , 44, 728, 167); //bigger frame [UIView commitAnimations]; 

The problem with this code is that it does not change the font dynamically.

+7
objective-c uilabel core-animation
source share
4 answers

All you have to do is apply the affine transform to the UILabel object.

 CGFloat scaleFactor = 2.0f; label.transform = CGAffineTransformMakeScale(scaleFactor, scaleFactor); // Enlarge by a factor of 2. 
+3
source share

Scaling your label, as suggested by others using the transform property, will work just fine. One thing to keep in mind is that as the label grows, the label does not grow, but only the rendered text, which means that it will appear “crazier” as it grows.

+1
source share

Try this method:

  • (void) setAnimationTransition: (UIViewAnimationTransition) transition forView: (UIView *) cache cache: (BOOL) cache

Options: Transition Transition to viewing. Possible values ​​are described in UIViewAnimationTransition.

View View of the application transition to.

cache If YES, the images before and after the image are displayed once and are used to create frames in the animation. Caching can improve performance, but if you set this parameter to YES, you should not update the view or its subitems during the transition. Updating a view and its children can affect the caching behavior and cause the contents of the view to display incorrectly (or in the wrong place) during animation. You must wait until the transition is complete to update the view.

If NO, the view and its contents should be updated for each frame of the transition animation, which can significantly affect the frame rate.

Discussion If you want to change the appearance of the view during the transition, for example, flip from one view to another, and then use the container view, an instance of UIView, as follows:

Start the animation block. Set the transition to the container view. Remove the view from the container view. Add a new view to the container view. Lock the animation block.

0
source share

Just change your label instead of changing fontSize.

0
source share

All Articles