UIButton用动画添加颜色

Pra*_*ari 6 iphone uibutton uicolor uianimation

我想要做的是,当用户点击按钮时,按钮应该用从底部到顶部的动画填充颜色.

我试过这个添加了颜色,但没有添加动画效果.

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) {
}];
Run Code Online (Sandbox Code Playgroud)

Mwe*_*ene -1

最好的解决方案是子类化 UIButton 并添加一个将背景图像的 alpha 值从 0 更改为 1 的方法。

或者,您可以重写 drawRect 方法并用颜色填充背景。