UIButton GIF背景图片

时间:2013-05-24 21:22:11

标签: objective-c

如何将GIF图片用作UIButton图片背景?

        UIImage *img1 = [UIImage imageNamed:@"btn_img1"];
        UIImage *img2 = [UIImage imageNamed:@"btn_img2"];
        UIImage *img3 = [UIImage imageNamed:@"btn_img3"];

        // GIF ImageView
        _btnGIF.imageView.animationImages = [[NSArray alloc] initWithObjects:img1, img2, img3, nil];
        _btnGIF.imageView.animationDuration = 0;
        [_btnGIF.imageView startAnimating];

        //[_btnGIF setBackgroundImage:GIF forState:UIControlStateNormal];

1 个答案:

答案 0 :(得分:1)

您需要使用图像启动按钮,以便正确创建它。

例如:

UIImage *img1 = [UIImage imageNamed:@"btn_img1"];
UIImage *img2 = [UIImage imageNamed:@"btn_img2"];
UIImage *img3 = [UIImage imageNamed:@"btn_img3"];

[_btnGIF setImage:img1 forState:UIControlStateNormal];


// GIF ImageView
_btnGIF.imageView.animationImages = [[NSArray alloc] initWithObjects:img1, img2, img3, nil];
_btnGIF.imageView.animationDuration = 0;
[_btnGIF.imageView startAnimating];