Iphone UIButton通过动画添加颜色
我想做的是,当用户单击按钮时,按钮应该从下到上用动画填充颜色 我尝试了添加颜色,但没有添加动画效果Iphone UIButton通过动画添加颜色,iphone,uibutton,uicolor,uianimation,Iphone,Uibutton,Uicolor,Uianimation,我想做的是,当用户单击按钮时,按钮应该从下到上用动画填充颜色 我尝试了添加颜色,但没有添加动画效果 float originalY = btn.frame.origin.y; float originalH = btn.bounds.size.height; [UIView animateWithDuration:3.0f delay:1.0f options:UIViewAnimationOptionTran
float originalY = btn.frame.origin.y;
float originalH = btn.bounds.size.height;
[UIView animateWithDuration:3.0f
delay:1.0f
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:^{
btn.frame = CGRectMake(btn.frame.origin.x, (originalY + originalH), btn.bounds.size.width, 0);
[btn setBackgroundImage:[UIImage imageNamed:@"Screen Shot 2012-11-07 at 4.22.30 PM.png"] forState:UIControlStateNormal];
[btn setTitleColor:[[UIColor alloc]initWithRed:38.0/255.0 green:38.0/255.0 blue:38.0/255.0 alpha:1.0] forState:UIControlStateNormal];
} completion:^(BOOL finished) {
}];
最好的解决方案是将UIButton子类化,并添加一个将背景图像的alpha值从0更改为1的方法
或者,您可以覆盖drawRect方法,在那里用颜色填充背景。我想您可能会这样做,我使用UIlabel它也可以用于UIButton
#import <QuartzCore/QuartzCore.h>
#导入
'theLabel.layer.backgroundColor=[UIColor whiteColor].CGColor
[UIView animateWithDuration:2.0动画:^{
label.layer.backgroundColor=[UIColor greenColor].CGColor;
}完成:NULL];'` 您是否在动画块之前设置了颜色?否我仅在动画块中设置了颜色。它被设置好了,只是动画没有出现。这不会改变底部到顶部的颜色-它可能会改变整个按钮的颜色,但我不认为这是问题…增加动画中的时间持续时间:它会显示效果,谢谢。