-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
[_keyboard.collectionView registerClass:[NibCell class] forCellWithReuseIdentifier:@"Cell"];
static NSString *identifier = @"Cell";
NibCell *cell = [self.keyboard.collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView * rampageGifImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, cell.frame.size.width, cell.frame.size.height)];
[rampageGifImage setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@.gif",[rampageGif objectAtIndex:indexPath.row]]]];
[cell.layer setCornerRadius:4];
[cell addSubview:rampageGifImage];
return cell;
}
答案 0 :(得分:1)
您可以在项目中通过Github添加SDWebImage来使用Gif Image。
试试这个,
#import "UIImage+GIF.h"
_imageViewAnimatedGif.image= [UIImage sd_animatedGIFNamed:@"YOURGIF_IMAGE"];
希望这会对你有所帮助。
答案 1 :(得分:1)
Try it. It is small category that could loads animated GIF. Also, jpg, png, etc..
#import "ViewController.h"
#import "UIImage+Gif.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView1;
@property (weak, nonatomic) IBOutlet UIImageView *imageView2;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Usage 1 : gifWidthData
NSData *data = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"f1" withExtension:@"gif"]];
self.imageView1.image = [UIImage gifWithData:data];
// Usage 2 : gifWidthURL
NSURL *url = [[NSBundle mainBundle] URLForResource:@"f2" withExtension:@"gif"];
self.imageView2.image = [UIImage gifWithURL:url];
}