美文网首页
使用bundle打包图片资源和xib

使用bundle打包图片资源和xib

作者: zhouluyao | 来源:发表于2020-10-21 11:32 被阅读0次

1、如何创建一个bundle:

iOS 如何把图片资源打包成bundle文件及遇到的坑

2、把图片资源,xib打包进bundle以后,如何使用?

2.1、加载本地的bundle

+ (NSBundle *)bundle {
    static NSBundle *bundle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        bundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:[self class]] pathForResource:@"ZLYKit" ofType:@"bundle"]];
    });
    return bundle;
}

2.2、获取bundle里面的图片资源

+ (UIImage *)imageNamed:(NSString *)name {
    UIImage *image = [UIImage imageNamed:name inBundle:self.bundle compatibleWithTraitCollection:nil];
    return image;
}

+ (UIImage *)imageNamed:(NSString *)name type:(NSString *)type {
    if (name.length == 0) return nil;
    int scale = (int)UIScreen.mainScreen.scale;
    if (scale < 2) scale = 2;
    else if (scale > 3) scale = 3;
    NSString *n = [NSString stringWithFormat:@"%@@%dx", name, scale];
    UIImage *image = [UIImage imageWithContentsOfFile:[self.bundle pathForResource:n ofType:type]];
    if (!image) image = [UIImage imageWithContentsOfFile:[self.bundle pathForResource:name ofType:type]];
    return image;
}

[self.leftImageView sd_setImageWithURL:[NSURL URLWithString:fileModel.courseImageUrl] placeholderImage:[ZLYUtilities imageNamed:@"place_holder_home_lesson"]];

2.3、获取bundle里面的xib资源

[_tableView registerNib:[UINib nibWithNibName:@"LYChatRoomImageTableViewCell" bundle:[ZLYUtilities bundle]] forCellReuseIdentifier:imageID];

相关文章

  • 使用bundle打包图片资源和xib

    1、如何创建一个bundle: iOS 如何把图片资源打包成bundle文件及遇到的坑[https://cloud...

  • iOS_Bundle资源文件包

    Bundle文件 Bundle 文件,简单理解,就是资源文件包。我们将许多图片、XIB、文本文件组织在一起,打包成...

  • React Native IOS打包步骤

    第一步:导出js bundle包和图片资源:供打包离线使用 我们需要将JS部分的代码和图片资源等打包导出,然后通过...

  • iOS14开发-数据存储

    Bundle 简单理解就是资源文件包,会将许多图片、xib、文本文件组织在一起,打包成一个 Bundle 文件,这...

  • iOS-Bundle

    什么是Bundle? Bundle就是资源文件包, 将我们使用的Xib, 图片, 其他文件组织在一起! Bundl...

  • 打包bundle资源文件

    序言:为了把图片文件、xib文件、文本文档跟源码放在一起给别人使用,我们可以把这些资源文件打包成bundle文件。...

  • 制作一个bundle

    前言 之前已经介绍了打包通用静态库,详情见打包通用静动态库。接下来制作一下包含图片,xib等资源的bundle。 ...

  • iOS SDK开发之图片资源Bundle打包

    iOS SDK开发项目中用到图片资源和xib,storyboatd资源,我们可以将这些资源全部归类到bundle文...

  • iOS 创建开源库时如何使用图片和xib资源

    参考文章 参考文章 使用xib的正确姿势 使用图片的正确姿势 首先创建bundle文件夹 将相应的图片资源文件放到...

  • 加载自定义bundle中资源

    bundle 存储资源(图片、xib、storyboard) 加载bundle有很多方式 .a静态库加载 动态库加载方式

网友评论

      本文标题:使用bundle打包图片资源和xib

      本文链接:https://www.haomeiwen.com/subject/otbsmktx.html