iosxib 设置图片_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"];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值