溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

iOS中如何顯示gif圖

發(fā)布時(shí)間:2021-09-28 10:13:09 來(lái)源:億速云 閱讀:203 作者:小新 欄目:編程語(yǔ)言

這篇文章主要介紹了iOS中如何顯示gif圖,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

顯示本地gif圖

SDWebImage和YYImage的顯示本地圖片代碼。

//load loacle gif image- (void)loadLocaleGifImage{ //sdwebimage [self labelFactoryWithFrame:CGRectMake(0, 80, kScreenWidth, 20) title:@"SDWebImage"]; NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"gif"]; NSData *gifData = [NSData dataWithContentsOfFile:path]; UIImageView *sdImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 100, kScreenWidth, kScreenHeight/3)]; sdImageView.image = [UIImage sd_animatedGIFWithData:gifData]; [self.view addSubview:sdImageView]; //yyImage show gif image [self labelFactoryWithFrame:CGRectMake(0, kScreenHeight/2 - 20, kScreenWidth, 20) title:@"yyImage"]; YYImage *yyimage = [YYImage imageNamed:@"test.gif"]; YYAnimatedImageView *yyImageView = [[YYAnimatedImageView alloc] initWithImage:yyimage]; yyImageView.frame = CGRectMake(0, kScreenHeight/2, kScreenWidth, kScreenHeight/3); [self.view addSubview:yyImageView];}

加載網(wǎng)絡(luò)的gif圖

SDWebImage和YYImage的加載網(wǎng)絡(luò)圖片代碼。

//download network gif image- (void)downloadNetworkGifImage{ //sdwebimage [self labelFactoryWithFrame:CGRectMake(0, 80, kScreenWidth, 20) title:@"SDWebImage"]; FLAnimatedImageView *sdImageView = [[FLAnimatedImageView alloc] initWithFrame:CGRectMake(0, 100, kScreenWidth, kScreenHeight/3)]; [sdImageView sd_setImageWithURL:[NSURL URLWithString:@"https://cache.yisu.com/upload/information/20201211/272/44763.gif"]]; [self.view addSubview:sdImageView]; //yyImage show gif image [self labelFactoryWithFrame:CGRectMake(0, kScreenHeight/2 - 20, kScreenWidth, 20) title:@"yyImage"]; YYImage *yyimage = [YYImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://cache.yisu.com/upload/information/20201211/272/44763.gif"]]]; YYAnimatedImageView *yyImageView = [[YYAnimatedImageView alloc] initWithImage:yyimage]; yyImageView.frame = CGRectMake(0, kScreenHeight/2, kScreenWidth, kScreenHeight/3); [self.view addSubview:yyImageView];}- (void)labelFactoryWithFrame:(CGRect)frame title:(NSString *)title{ UILabel *label = [[UILabel alloc] initWithFrame:frame]; label.textAlignment = NSTextAlignmentCenter; label.textColor = [UIColor blackColor]; label.font = [UIFont systemFontOfSize:14]; label.text = title; [self.view addSubview:label];}

Podfile文件內(nèi)容

platform :ios, '10.0'inhibit_all_warnings!target 'GifDemo' dopod 'YYImage'pod 'SDWebImage/GIF'pod 'FLAnimatedImage'end

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“iOS中如何顯示gif圖”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI