iOS组件化 如何在项目中使用xib、storyboard以及图片等资源

注:组件化之后 发现原来的资源都无法正常的加载了 问题的原因就是路径发生了改变 所以想正确的加载资源 必须把路径修改正确


一.图片资源路径

以WKWebTest 

资源都是放在Assets下



获取图片的路径

//stringName 就是你图片资源的名字

- (UIImage*)setResourcesPath:(NSString*)stringName {

    //------------------路径

    NSURL *urlClassBundle = [[NSBundle bundleForClass:[self class]] URLForResource:@"WKWebTest" withExtension:@"bundle"];

    NSBundle*urlBundle = [NSBundlebundleWithURL:urlClassBundle];

    UIImage *image = [UIImage imageNamed:stringName inBundle:urlBundle compatibleWithTraitCollection:nil];

    returnimage;

}

二.storyboard路径


- (UIViewController*)loadStoryboard:(UIViewController*)viewController {

 //获取pods中的路径

    NSBundle*currentBundle = [NSBundlebundleForClass:[viewControllerclass]];

    NSURL*bundleUrl = [currentBundleURLForResource:@"SXLoginCompont"withExtension:@"bundle"];

    NSBundle *dle = [NSBundle bundleWithURL:bundleUrl];

   //storyboardv创建

    UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"SXLogin" bundle:dle];

    return [mainStoryBoard instantiateViewControllerWithIdentifier:@"SXLoginViewController"];

}

三.xib路径

  下面简易的写了下 具体用法按照自己实际怎么用就怎么写

    UINib *loadNib = [UINib nibWithNibName:@"SXLogin" bundle:dle];

    return [_tableView registerNib:loadNib forCellReuseIdentifier:@"这里写cell的Identifierin"];

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容