Mac开发 - NSImageView加载Gif图片

  • 将资源文件拖入项目
  • 设置NSImageView的animates为YES
  • 使用代码设置image
- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.loginAnimateView.image = [[NSImage alloc] initWithData:
                                   [NSData dataWithContentsOfFile:
                                    [[NSBundle mainBundle] pathForResource:@"xs_login_animate" ofType:@"gif"]]];
}

对于pathForResource:加载出来的资源路径为nil可以参考这篇文章: Mac开发 - NSBundle 加载资源文件

你可能感兴趣的:(Mac开发 - NSImageView加载Gif图片)