前言:
1、也算是花了点时间去弄这个东西呢。
2、恶心,不想说话
在制作 FrameWork 的时候 Mach-O Type 选择有两个,本篇是 Dynamic Library。
Static 方式没有配置的话,直接运行是不会崩溃的,只是读不到文件。Dynamic方式没有配置的话,运行会崩溃。
开始
图片高清,Command + “+” 放大阅读
1、创建Bundle工程

2、修改 Base SDK

3、修改 COMBINE_HIDPI_IMAGES

4、修改 Skip Install

5、引入图片文件

6、创建Plist文件

7、创建XIB文件

8、拖放按钮 创建代码文件 连线

9、拖放按钮 创建代码文件 连线
为什么要在这里搞代码文件呢,因为代码文件要和XIB连线,这样弄出来的XIB才会有意义,所以在打包工程里面, 直接创建代码文件进行连线,然后把代码文件拖到FrameWork里。最好应该是先创建一个App,把所有的功能都写好,然后 分别创建 Bundle工程和FrameWork工程,把代码和资源文件分开,再合并,做成一个完整的FrameWork。

10、检查文件

11、编译bundle

12、创建FrameWork项目

13、修改 Build Active Architecture Only

14、修改 Mach-O Type
注意,这里是动态库。

15、引入代码

16、引入bundle

17、写代码
写代码访问资源文件,这里是动态库的资源文件访问方式,完整的代码在文章末尾。

18、暴露文件

19、暴露文件

20、编译FrameWork文件,设置Scheme
做这一步的目的是为了让这个FrameWork 同时支持真机和模拟器运行。

21、编译模拟器版本
随便选个模拟器,按下 Command + B

22、编译真机版本
选择“Generic iOS Device”,按下 Command + B

23、合并
合并使用到的命令,根据你的FrameWork名称做相应的替换。
lipo -create Release-iphoneos/Yuency.framework/Yuency Release-iphonesimulator/Yuency.framework/Yuency -output Yuency

24、寻找周杰伦

25、创建App工程进行测试

26、对引入的fram进行设置

27、Command + R

必要的代码
SunView.h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface SunView : UIView
/// 中间按钮
@property (weak, nonatomic) IBOutlet UIButton *buttonCenter;
- (instancetype)initWithFrame:(CGRect)frame;
+ (instancetype)initFromXIB;
+ (void)showPlistContent;
@end
NS_ASSUME_NONNULL_END
SunView.m
#import "SunView.h"
@implementation SunView
- (IBAction)actionButton:(UIButton *)sender {
NSLog(@"按钮点击相应!");
}
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
NSBundle *dynamicBundle = [NSBundle bundleForClass:[SunView class]];
NSURL *bundelURL = [dynamicBundle URLForResource:@"Work" withExtension:@"bundle"];
NSBundle *myBundle = [NSBundle bundleWithURL:bundelURL];
NSString *path = [myBundle pathForResource:@"a" ofType:@"jpg"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
imageView.image = [UIImage imageWithContentsOfFile:path];
[self addSubview:imageView];
}
return self;
}
+ (instancetype)initFromXIB {
NSBundle *dynamicBundle = [NSBundle bundleForClass:[SunView class]];
NSURL *bundelURL = [dynamicBundle URLForResource:@"Work" withExtension:@"bundle"];
NSBundle *myBundle = [NSBundle bundleWithURL:bundelURL];
SunView *view = [myBundle loadNibNamed:@"SunView" owner:nil options:nil].firstObject;
return view;
}
+ (void)showPlistContent {
NSBundle *dynamicBundle = [NSBundle bundleForClass:[SunView class]];
NSURL *bundelURL = [dynamicBundle URLForResource:@"Work" withExtension:@"bundle"];
NSBundle *myBundle = [NSBundle bundleWithURL:bundelURL];
NSString *p = [myBundle pathForResource:@"b" ofType:@"plist"];
NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:p];
NSLog(@"文件内容: %@", dic);
}
@end
网友评论