我想将动画放到自定义UIButton的标题上,以便数字(每个标题显示一个随机分配的数字)将旋转。我怎样才能做到这一点?
问题是我不想使用翻转数字图像来执行此操作。我想知道是否还有其他办法。
答案 0 :(得分:4)
假设您有一个名为flipLabelButton
的按钮作为IBOutlet
连接到视图控制器,您可以使用此代码将按钮设置为新标签:
- (IBAction)flipLabelText:(id)sender {
NSString *newText = [NSString stringWithFormat:@"%d", rand() % 100];
[UIView beginAnimations:@"flipbutton" context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.flipLabelButton cache:YES];
[self.flipLabelButton setTitle:newText forState:UIControlStateNormal];
[UIView commitAnimations];
}