使用SDWebImageView加載gif圖片

- (void)viewDidLoad {
    [
super viewDidLoad];
   
// Do any additional setup after loading the view, typically from a nib.
    [
self initLoadingImageView];
}

- (
void)initLoadingImageView

{

   
NSString  *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:@"2.gif" ofType:nil];
   
   
NSData  *imageData = [NSData dataWithContentsOfFile:filePath];
   
   
self.loadingImageView = [[UIImageView alloc]init];
       
self.loadingImageView.frame = CGRectMake(0, 0, self.view.frame.size.width self.view.frame.size.height);
   
   
self.loadingImageView.backgroundColor = [UIColor blueColor];
   
//第一種方法使用imageData加載
   
self.loadingImageView.image = [UIImage sd_animatedGIFWithData:imageData];
   
//第二種方法使用圖片名字加載
    //
self.loadingImageView.image = [UIImage sd_animatedGIFNamed:@"2"];
   
    [
self.view addSubview:self.loadingImageView];
   
    [
self.view bringSubviewToFront:self.loadingImageView];
   
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章