在uibutton上的动画gif

时间:2013-01-22 17:32:17

标签: iphone uibutton gif animated

我使用这个代码,工作,图像160x148的大小,但图像按钮在所有屏幕上都非常大!

UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:    
                               [UIImage imageNamed:@"button1.png"],
                               [UIImage imageNamed:@"button2.png"],
                               [UIImage imageNamed:@"button3.png"],
                               [UIImage imageNamed:@"button4.png"], nil];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[yourButton addSubview: animatedImageView];

如何修复?

2 个答案:

答案 0 :(得分:2)

图像很大,因为您调用了initWithFrame:并传入了视图的边界。将其更改为不同大小的矩形,例如:

CGRectMake(0, 0, 160, 148)

...然后根据需要重新定位。

答案 1 :(得分:0)

试试此代码。它将帮助您找到正确的解决方案。

 UIImage *myimage=UIImage imageNamed:@"button1.png";
Button.imageview.image=myimage;