【问题标题】:Add an image to my button in ios is blue在ios中向我的按钮添加图像是蓝色的
【发布时间】:2013-08-29 07:18:55
【问题描述】:

我的按钮中有一个 gif,但它只显示为蓝色框。

 (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
    {
    //[self setTitle:@"Register" forState:UIControlStateNormal];
    [self setBackgroundColor:[UIColor whiteColor]];
    [self setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];



    [self setImage:[UIImage imageNamed:@"Person.gif"] forState:UIControlStateNormal];//setting image on button.
}
return self;

}

图像已正确添加到 xcode。什么给了?

【问题讨论】:

  • 尝试使用UIImageView显示gif。
  • iOS 不支持 GIF 图片
  • @chris 你必须对你的问题的答案做出回应,这不是获得帮助的方式。在列表中,您回复为您提供有关您的问题的答案的用户。谢谢

标签: ios objective-c ios6 uibutton


【解决方案1】:

不支持 iOS GIF 图像,因此如果您希望设置带有动画的图像,请执行以下代码:-

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

有关更多信息,请查看有关 iOS 支持的 GIF 的波纹管链接:-

Discussions

Display animated GIF in iOS

【讨论】:

    【解决方案2】:

    尝试设置[按钮背景图像],它会为你设置任何格式的图像

    【讨论】:

      【解决方案3】:

      SDWebImage 声称支持动画 gif!

      检查一下:

      https://github.com/rs/SDWebImage

      【讨论】:

        猜你喜欢
        • 2015-07-01
        • 1970-01-01
        • 2019-06-29
        • 2020-07-28
        • 1970-01-01
        • 2011-11-04
        • 2015-03-28
        • 2013-07-05
        • 1970-01-01
        相关资源
        最近更新 更多