IOS

iOS framework快捷开发(使用Pods)

2018-12-06  本文已影响10人  _蓝星

主要记录framework快捷开发的工程创建以及配置,以及sdk开发过程中pod的具体使用方法。

创建一个framework工程,并添加pod。pod会为我们生成一个workspace,然后编写podfile,增加对framework工程target的支持。

注:如果编译失败,pod中的三方库显示不能使用,要重新pod install。

framework工程的一些配置,可以参考(iOS framework 静态库制作)

1.添加framework工程.png
workspace 'FrameworkTestDemo.xcworkspace'              #指定workspace
inhibit_all_warnings!        #忽略警告
use_frameworks!

def commpod                     #宏定义几个target都要用的的pod
    pod 'Masonry'
    pod 'YYCategories'
    pod 'YYModel'
end

target 'FrameworkTestDemo' do
    project 'FrameworkTestDemo'
    commpod
#    pod 'AFNetworking' 添加主工程自己要用的pod库

end

target 'TestFramework' do
    project 'TestFramework/TestFramework'
    commpod
end
#import "TestView.h"
#import "Masonry.h"

@interface TestView ()

@property (nonatomic, strong) UIImageView *testImage;

@end

@implementation TestView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        _testImage = [[UIImageView alloc] init];
        _testImage.image = [self getImageFromBundleWithName:@"WechatIMG3"];
        [self addSubview:_testImage];
        [_testImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.equalTo(self);
        }];
        
    }
    return self;
}

-(UIImage *)getImageFromBundleWithName:(NSString *)imgName{
    NSString * bundlePath = [[NSBundle mainBundle] pathForResource:@"frameworkImages" ofType:@"bundle"];
    NSBundle * bundle = [NSBundle bundleWithPath:bundlePath];
//    NSString * imgPath = [bundle pathForResource:[NSString stringWithFormat:@"%@@%.0fx",imgName,[UIScreen mainScreen].scale] ofType:@"png"];
    NSString * imgPath = [bundle pathForResource:[NSString stringWithFormat:@"%@",imgName] ofType:@"png"];
    UIImage *image = [UIImage imageWithContentsOfFile:imgPath];
    return image;
}

@end
上一篇下一篇

猜你喜欢

热点阅读