IT/Ⅰ. IOS

[IOS] GIF, SVG, APNG 이미지 사용

혁준7519 2025. 5. 22. 22:47

GIF, APNG : SDWebImage 라이브러리 사용

 

SVG : SVGKit 라이브러리 사용

 

 

이미지는 앱 번들에 포함

 

 

  • GIF, APNG : ImageView 를 포함시켜 SDAnimatedImageView 클래스로 지정
  • SVG : UIView 를 포함시켜 SVGKFastImageView 클래스로 지정

 

 

ViewController.h

#import <UIKit/UIKit.h>
#import "SDWebImage/SDAnimatedImageView.h"
#import "SDWebImage/SDAnimatedImage.h"
#import "SVGKit.h"
#import "SVGKImage.h"
#import "SVGKFastImageView.h"
 
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet SDAnimatedImageView *imgGif;
@property (strong, nonatomic) IBOutlet SVGKFastImageView *imgSvg;
@property (strong, nonatomic) IBOutlet SDAnimatedImageView *imgApng;
 
 
@end
cs

 

 

ViewController.m

@implementation ViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
 
    // GIF
    NSString *gifPath = [[NSBundle mainBundle] pathForResource:@"gif_sample" ofType:@"gif"];
    NSData *gifData = [NSData dataWithContentsOfFile:gifPath];
    [self.imgGif setImage:[SDAnimatedImage imageWithData:gifData]];
 
    // SVG
    SVGKImage *svgImage = [SVGKImage imageNamed:@"svg_sample.svg"];
    [self.imgSvg setImage:svgImage];
    
    // APNG
    NSString *apngPath = [[NSBundle mainBundle] pathForResource:@"apng_sample" ofType:@"png"];
    NSData *apngData = [NSData dataWithContentsOfFile:apngPath];
    [self.imgApng setImage:[SDAnimatedImage imageWithData:apngData]];
}
 
 
@end
 
cs