iOS 自定义库文件

来源:互联网 发布:淘宝联盟规则 编辑:程序博客网 时间:2024/06/05 11:15

第一步:创建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 = [superinit];

   if (self) {

        self.layer.cornerRadius =10;

        self.layer.masksToBounds =YES;

       self.frame = frame;

       NSURL *url = [NSURLURLWithString:_urlString];

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

       dispatch_async(queuewww, ^{

           NSData *data = [NSDatadataWithContentsOfURL:url];

           UIImage *imga = [UIImageimageWithData: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工程就可以使用了;



0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 家里种葱老是死怎么办 非洲菊生虫子了怎么办 多肉的花剪下来怎么办 结石痛怎么办怎么止疼 喝玫瑰花茶胃疼怎么办 卡地亚戒指掉色怎么办 苹果8plus掉电快怎么办 苹果8plus耗电快怎么办 卡地亚戒指划痕怎么办 苹果手机玫瑰金掉色怎么办 14k玫瑰金掉色怎么办 卡地亚手镯掉色怎么办 手机掉油漆里了怎么办 黄金戴久了变黑怎么办 玫瑰金褪色不亮了怎么办 黄金带久了不亮怎么办 玉石带久了不亮怎么办 手表带久了不亮怎么办 蜜蜡带久了不亮怎么办 钛钢首饰不亮了怎么办 潘多拉玫瑰金戒指褪色了怎么办 金色手表漆掉了怎么办 玫瑰金表带褪色后怎么办 K金褪色或泛黄怎么办 钛钢玫瑰金变黑怎么办 玫瑰金手镯掉色了怎么办 彩金颜色不亮了怎么办 玫瑰金链子黑了怎么办 18k玫瑰金变黑了怎么办 玫瑰金戒指遇到火变黑怎么办 18k白金发黄了怎么办 18k金掉色后怎么办吗 dw手表金色掉漆怎么办 dw玫瑰金手表褪色怎么办 dw金色表带黑了怎么办 机械表机芯坏了怎么办 银镀玫瑰金褪色怎么办 苹果七p玫瑰金掉漆怎么办 美度镀金表掉色怎么办 吃了发黑的香菇怎么办 脸上的皮肤暗黄怎么办