iOS Framework 包含 圖片 Plist XIB 靜態(tài)庫

前言:

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工程

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才會(huì)有意義,所以在打包工程里面, 直接創(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 修改 Mach-O Type.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、引入FrameWork 1

26、對(duì)引入的fram進(jìn)行設(shè)置 .png

27、引入FrameWork 2

27 添加靜態(tài)framewor.png

28、Command + R

28 Command + R.png

必要的代碼

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

上一篇

iOS Framework 包含 圖片 Plist XIB 動(dòng)態(tài)庫

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容