iOS 自定义库文件

第一步:创建framworking工程


第二步

在工程里封装一个自定义类;

#import <UIKit/UIKit.h>


@interface imageview : UIImageView

-(instancetype)initWithFrame:(CGRect)frame urlString:(NSString *)_urlString;

@end


#import "imageview.h"


@implementation imageview

-(instancetype)initWithFrame:(CGRect)frame urlString:(NSString *)_urlString{

    self = [super init];

    if (self) {

        self.layer.cornerRadius = 10;

        self.layer.masksToBounds = YES;

        self.frame = frame;

        NSURL *url = [NSURL URLWithString:_urlString];

        dispatch_queue_t queuewww=dispatch_queue_create("test", NULL);

        dispatch_async(queuewww, ^{

            NSData *data = [NSData dataWithContentsOfURL:url];

            UIImage *imga = [UIImage imageWithData:data];

            

            dispatch_sync(dispatch_get_main_queue(), ^{

                

                self.image = imga;

                

                

            });

        });

        

    }

    return self;

}


第三步:设置Build Phase

将 Header / Project中的.h文件拖入Public中

如下图


设置Build Settings

a.将Linking / Mach Type 设置为 Static Library

b.将Packaging / Defines Module 设置为NO;

如下图


第三步,添加Aggregate


在Aggregate  的Build Phase添加Run Script并修改其中的shell 对话框内容

如图


内容如下:修改FMK_NAME值为自己自定义类名;如FMK_NAME = ...

# Sets the target folders and the final framework product.

# 如果工程名称和FrameworkTarget名称不一样的话,要自定义FMKNAME

# 例如: FMK_NAME = "MyFramework"

FMK_NAME=Myframworking

# Install dir will be the final output to the framework.

# The following line create it in the root folder of the current project.

INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework

# Working dir will be deleted after the framework creation.

WRK_DIR=build

DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework

SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework

# -configuration ${CONFIGURATION}

# Clean and Building both architectures.

xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build

xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build

# Cleaning the oldest.

if [ -d "${INSTALL_DIR}" ]

then

rm -rf "${INSTALL_DIR}"

fi

mkdir -p "${INSTALL_DIR}"

cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"

# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.

lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"

rm -r "${WRK_DIR}"

open "${INSTALL_DIR}"


第四步:

(将模拟器调为Generic IOS Device模式)

1.先运行framworking

2.在运行Aggregate

之后会弹出新创建的自定义库文件夹。


恭喜你已经成功创建属于自己的框架。

若需调用框架,只需要将自定义库文件夹中product中的程序拖入你的X-code工程就可以使用了;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值