我目前正在开发一个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.