带有动画gif图像的IOS UIButton
如何将动画gif文件添加为UIButton的默认图像。 我添加了gif文件作为按钮图像。但它不是动画带有动画gif图像的IOS UIButton,ios,cocoa,Ios,Cocoa,如何将动画gif文件添加为UIButton的默认图像。 我添加了gif文件作为按钮图像。但它不是动画 谢谢。不支持iOS.gif文件格式。因此,避免在iOS中使用.gif文件动画gif在iphone中不会动画。。您应该将UIImageView作为子视图添加到UIButton,从GIF中提取所有图像,并使用UIImageView动画制作动画 UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.b
谢谢。不支持iOS.gif文件格式。因此,避免在iOS中使用.gif文件动画gif在iphone中不会动画。。您应该将UIImageView作为子视图添加到UIButton,从GIF中提取所有图像,并使用UIImageView动画制作动画
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"image1.gif"],
[UIImage imageNamed:@"image2.gif"],
[UIImage imageNamed:@"image3.gif"],
[UIImage imageNamed:@"image4.gif"], nil];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[yourButton addSubview: animatedImageView];
您应该探索使用
UIButton
的替代方法,因为它不允许这种定制。例如,您可以为按钮使用
UIImageView`并为“触摸结束”事件设置操作。您不能只加载gif文件。将gif的每一帧保存到一个单独的图像文件(png或类似文件)-例如,您可以使用photoshop执行此操作,然后使用animationImages将其加载到UIImage中并执行StartAnimation。可能会帮助您吗?不,这与我的问题无关。。这是按下按钮时的动画。我想将默认图像设置为动画gif。我必须创建哪种类型的按钮,自定义?您必须将gif中的所有图像作为单独的文件添加到xcode bundle toolet us中。您好,请在回答中添加一些代码。这真的很有帮助。谢谢,请将0.1 BTC发送给3DkHfAKrBtYqRUQ9ka7FS11ogfYWf7fLyU,我将提供示例代码。