setBackgroundImage:forState:animation / transition?

时间:2014-02-07 06:39:55

标签: ios objective-c uibutton uikit-transitions

我正在使用setBackgroundImage:forState:这样来为各种状态着色背景图像的颜色:

[myButton setBackgroundImage:genericImage forStates:UIControlStateNormal];
[myButton setBackgroundImage:buttonBackgroundPressed  
                   forStates:UIControlStateHighlighted];

是否有直接动画/应用淡入/淡出持续时间过渡到此方法的方法?

1 个答案:

答案 0 :(得分:2)

这个适用于我:

-(void) init{
  [myButton addTarget:self action:@selector(touchUp:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)touchUp:(id)sender
{
  UIButton* btn = sender;
  [UIView animateWithDuration:1.0 animations:^{
    btn.alpha = 0.5;
  }];
}