Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enlarge dynamically an UILabel (label and font size)?

Im currently working on an iPhone project. I want to enlarge dynamically an UILabel in Objective-C like this:

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

How is this possible? I thought I have to do it with CoreAnimation, but I didn't worked. 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 doesn't change the fontsize dynamically.

like image 984
Flocked Avatar asked Mar 23 '10 01:03

Flocked


People also ask

How do you change the font size on UILabel?

To change the font or the size of a UILabel in a Storyboard or . XIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.

How do I change dynamic font size in Swift?

In Interface Builder, select the text style from the Font menu, then select the Automatically Adjust Font checkbox to the right of Dynamic Type.


2 Answers

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

CGFloat scaleFactor = 2.0f;
label.transform = CGAffineTransformMakeScale(scaleFactor, scaleFactor); // Enlarge by a factor of 2.
like image 140
Mark Adams Avatar answered Sep 29 '22 06:09

Mark Adams


Scaling your label as suggested by others using the transform property will work great. One thing to keep in mind is that as the label gets larger, the font is not increasing, but just the rendered text, which means it will appear "fuzzier" as it gets larger.

like image 28
gschandler Avatar answered Sep 29 '22 06:09

gschandler