【问题标题】:How to animate UIButton background color如何为 UIButton 背景颜色设置动画
【发布时间】:2010-08-24 08:17:46
【问题描述】:

我想将 UIButton 背景颜色从黑色更改为白色。但我想在动画中改变它。例如...黑色>灰色>白色。 iPhone SDK中有什么简单的方法吗?谢谢你。

【问题讨论】:

    标签: iphone objective-c iphone-sdk-3.0


    【解决方案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】:

      属性 backgroundColor 自 3.2 SDK 起可设置动画。

      【讨论】:

        猜你喜欢
        • 2022-12-23
        • 2011-04-15
        • 1970-01-01
        • 2018-06-29
        • 1970-01-01
        • 2016-01-02
        • 1970-01-01
        • 2011-06-13
        • 2019-03-01
        相关资源
        最近更新 更多