前言:
1、FrameWork 使用靜態(tài)和動(dòng)態(tài)的方式在 Command R 的時(shí)候還是有點(diǎn)區(qū)別的
2、本篇繼續(xù)上一篇,使用靜態(tài)的方式做一個(gè)FrameWork
3、不厭其煩地、重復(fù)地、玩著這個(gè)庫。
在制作 FrameWork 的時(shí)候 Mach-O Type 選擇有兩個(gè),本篇是 Static Librar。
Static 方式?jīng)]有配置的話,直接運(yùn)行是不會(huì)崩潰的,只是讀不到文件。Dynamic方式?jīng)]有配置的話,運(yùn)行會(huì)崩潰。
開始
圖片高清,Command + “+” 放大閱讀
1、創(chuàng)建Bundle工程

2、修改 Base SDK

3、修改 COMBINE_HIDPI_IMAGES

4、修改 Skip Install

5、引入圖片文件

6、創(chuàng)建Plist文件

7、創(chuàng)建XIB文件

8、拖放按鈕 創(chuàng)建代碼文件 連線

9、拖放按鈕 創(chuàng)建代碼文件 連線
為什么要在這里搞代碼文件呢,因?yàn)榇a文件要和XIB連線,這樣弄出來的XIB才會(huì)有意義,所以在打包工程里面, 直接創(chuàng)建代碼文件進(jìn)行連線,然后把代碼文件拖到FrameWork里。最好應(yīng)該是先創(chuàng)建一個(gè)App,把所有的功能都寫好,然后 分別創(chuàng)建 Bundle工程和FrameWork工程,把代碼和資源文件分開,再合并,做成一個(gè)完整的FrameWork。

10、檢查文件

11、編譯bundle

12、創(chuàng)建FrameWork項(xiàng)目

13、修改 Build Active Architecture Only

14、修改 Mach-O Type
注意,這里是靜態(tài)庫。

15、引入代碼

16、引入bundle

17、寫代碼
寫代碼訪問資源文件,這里是靜態(tài)庫資源的訪問方式,完整的代碼在文章末尾。

18、暴露文件

19、暴露文件

20、編譯FrameWork文件,設(shè)置Scheme
做這一步的目的是為了讓這個(gè)FrameWork 同時(shí)支持真機(jī)和模擬器運(yùn)行。

21、編譯模擬器版本
隨便選個(gè)模擬器,按下 Command + B

22、編譯真機(jī)版本
選擇“Generic iOS Device”,按下 Command + B

23、合并
合并使用到的命令,根據(jù)你的FrameWork名稱做相應(yīng)的替換。
lipo -create Release-iphoneos/Yuency.framework/Yuency Release-iphonesimulator/Yuency.framework/Yuency -output Yuency

24、尋找周杰倫

25、創(chuàng)建App工程進(jìn)行測試

26、引入FrameWork 1

27、引入FrameWork 2

28、Command + R

必要的代碼
SunView.h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface SunView : UIView
/// 中間按鈕
@property (weak, nonatomic) IBOutlet UIButton *buttonCenter;
- (instancetype)initWithFrameStatic:(CGRect)frame;
+ (instancetype)initFromXIBStatic;
+ (void)showPlistContentStatic;
@end
NS_ASSUME_NONNULL_END
SunView.m
#import "SunView.h"
@implementation SunView
- (IBAction)actionButton:(UIButton *)sender {
NSLog(@"按鈕點(diǎn)擊相應(yīng)!");
}
- (instancetype)initWithFrameStatic:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
NSString *bundlePaht = [[NSBundle mainBundle] pathForResource:@"Yuency.framework/Work" ofType:@"bundle"];
NSBundle *myBundle = [NSBundle bundleWithPath:bundlePaht];
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)initFromXIBStatic {
NSString *bundlePaht = [[NSBundle mainBundle] pathForResource:@"Yuency.framework/Work" ofType:@"bundle"];
NSBundle *myBundle = [NSBundle bundleWithPath:bundlePaht];
SunView *view = [myBundle loadNibNamed:@"SunView" owner:nil options:nil].firstObject;
return view;
}
+ (void)showPlistContentStatic {
NSString *bundlePaht = [[NSBundle mainBundle] pathForResource:@"Yuency.framework/Work" ofType:@"bundle"];
NSBundle *myBundle = [NSBundle bundleWithPath:bundlePaht];
NSString *p = [myBundle pathForResource:@"b" ofType:@"plist"];
NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:p];
NSLog(@"文件內(nèi)容: %@", dic);
}
@end