前言:
1输吏、也算是花了點(diǎn)時(shí)間去弄這個(gè)東西呢卦洽。
2、惡心吃警,不想說話
在制作 FrameWork 的時(shí)候 Mach-O Type 選擇有兩個(gè)糕篇,本篇是 Dynamic Library。
Static 方式?jīng)]有配置的話酌心,直接運(yùn)行是不會崩潰的拌消,只是讀不到文件。Dynamic方式?jīng)]有配置的話安券,運(yùn)行會崩潰墩崩。
開始
圖片高清,Command + “+” 放大閱讀
1侯勉、創(chuàng)建Bundle工程
1 新建工程.png
2鹦筹、修改 Base SDK
2 .png
3、修改 COMBINE_HIDPI_IMAGES
3.png
4址貌、修改 Skip Install
4.png
5铐拐、引入圖片文件
5 拖入圖片.png
6徘键、創(chuàng)建Plist文件
6 新建plist文件.png
7、創(chuàng)建XIB文件
7 新建XIB.png
8遍蟋、拖放按鈕 創(chuàng)建代碼文件 連線
8 拖入按鈕.png
9吹害、拖放按鈕 創(chuàng)建代碼文件 連線
為什么要在這里搞代碼文件呢,因?yàn)榇a文件要和XIB連線匿值,這樣弄出來的XIB才會有意義赠制,所以在打包工程里面, 直接創(chuàng)建代碼文件進(jìn)行連線挟憔,然后把代碼文件拖到FrameWork里钟些。最好應(yīng)該是先創(chuàng)建一個(gè)App,把所有的功能都寫好绊谭,然后 分別創(chuàng)建 Bundle工程和FrameWork工程政恍,把代碼和資源文件分開,再合并达传,做成一個(gè)完整的FrameWork篙耗。
9 拖入按鈕.png
10、檢查文件
10 確認(rèn)過眼神.png
11宪赶、編譯bundle
11 尋找bundle.png
12宗弯、創(chuàng)建FrameWork項(xiàng)目
12 創(chuàng)建新項(xiàng)目.png
13、修改 Build Active Architecture Only
13 build arch.png
14搂妻、修改 Mach-O Type
注意蒙保,這里是動態(tài)庫婶芭。
14 動態(tài)庫.png
15荠呐、引入代碼
15 引入代碼.png
16、引入bundle
16 引入bundle.png
17洽糟、寫代碼
寫代碼訪問資源文件扁瓢,這里是動態(tài)庫的資源文件訪問方式详恼,完整的代碼在文章末尾。
17 訪問文件.png
18引几、暴露文件
18 暴露文件1.png
19昧互、暴露文件
19 暴露名稱.png
20、編譯FrameWork文件伟桅,設(shè)置Scheme
做這一步的目的是為了讓這個(gè)FrameWork 同時(shí)支持真機(jī)和模擬器運(yùn)行硅堆。
20 編譯 設(shè)置shcema.png
21、編譯模擬器版本
隨便選個(gè)模擬器贿讹,按下 Command + B
21 模擬器編譯.png
22渐逃、編譯真機(jī)版本
選擇“Generic iOS Device”,按下 Command + B
22 真機(jī)編譯.png
23民褂、合并
合并使用到的命令茄菊,根據(jù)你的FrameWork名稱做相應(yīng)的替換疯潭。
lipo -create Release-iphoneos/Yuency.framework/Yuency Release-iphonesimulator/Yuency.framework/Yuency -output Yuency
23 合并包.png
24、尋找周杰倫
24 包.png
25面殖、創(chuàng)建App工程進(jìn)行測試
25 創(chuàng)建App工程 進(jìn)行測試.png
26竖哩、對引入的fram進(jìn)行設(shè)置
26 設(shè)置庫.png
27、Command + R
27 完工.png
必要的代碼
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(@"按鈕點(diǎn)擊相應(yīng)!");
}
- (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(@"文件內(nèi)容: %@", dic);
}
@end