How to animate UIButton background color

坚强是说给别人听的谎言 提交于 2019-12-22 00:17:41

问题


I want to change the UIButton background color from black to white color. But I want to change it in animation. For example... black > grey > white. Is there any simple way to do so in iPhone SDK? thank you.


回答1:


UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 300, 50)];
    [button setTitle:@"hi" forState:UIControlStateNormal];
    [button setBackgroundColor:[UIColor blackColor]];
    [self.view addSubview:button];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2.5];
    button.backgroundColor = [UIColor whiteColor];
    [UIView commitAnimations];



回答2:


Property backgroundColor is animateable since 3.2 SDK.



来源:https://stackoverflow.com/questions/3554612/how-to-animate-uibutton-background-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!