我目前正在从事一个 iPhone 项目。我想像这样在 Objective-C 中动态放大 UILabel:
alt text http://img268.imageshack.us/img268/9683/bildschirmfoto20100323u.png
这怎么可能?我以为我必须用CoreAnimation来做,但我没有工作。这是我试过的代码:
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];
此代码的问题在于它不会动态更改字体大小。
最佳答案
您需要做的就是对 UILabel
对象应用仿射变换。
CGFloat scaleFactor = 2.0f;
label.transform = CGAffineTransformMakeScale(scaleFactor, scaleFactor); // Enlarge by a factor of 2.
关于objective-c - 如何动态放大 UILabel(标签和字体大小)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2497007/