-1

如何使用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];
4

1 回答 1

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];
于 2013-05-24T22:39:52.493 回答