objective-c – 如何动态放大UILabel(标签和字体大小)?

前端之家收集整理的这篇文章主要介绍了objective-c – 如何动态放大UILabel(标签和字体大小)?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前正在开发一个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];

代码的问题在于它不会动态更改fontsize.

解决方法

您需要做的就是将仿射变换应用于UILabel对象.
CGFloat scaleFactor = 2.0f;
label.transform = CGAffineTransformMakeScale(scaleFactor,scaleFactor); // Enlarge by a factor of 2.
原文链接:https://www.f2er.com/c/118849.html

猜你在找的C&C++相关文章