Cocoapods创建库

1、在githud创建一个仓库

Cocoapods创建库_第1张图片

2、clone到本地目录下

wangsheongdeMBP:~ long$ cd "保存的路径"

wangsheongdeMBP:GIT王胜龙 long$ git clone “仓库git地址”

clone后在SLColor下存在2个文件(README,LICENSE),在当前目录创建SLColor目录,在SLColor下添加Classes目录

3、把之前写好的UIColor+SLColor文件放入到Classes目录下

4、制作SLColor.podspec

wangsheongdeMBP:GIT王胜龙 long$ cd "第一个SLColor目录下"                wangsheongdeMBP:SLColor long$ pod spec create “podspec的文件名(这里使用的相同的SLColor)”

5、打开SLColor.podspec填写相关信息

Spec Metadata (库的相关信息)

Spec License (许可证相关信息)

Author Metadata(作者相关信息)

Source Code (源代码相关信息)

Resources (资源相关信息)

Project Linking(工程需要的链接frameworks和library)

Project Settings(工程相关的配置文件设置)

Pod::Spec.new do |s|

s.name    = 'SLColor'

s.version  = '0.0.1'

s.ios.deployment_target = '7.0'

s.license  =  { :type => 'MIT', :file => 'LICENSE' }

s.summary  = 'UIColor 的扩展'

s.homepage = 'https://github.com/wangshenglong/SLColor.git'

s.authors  = { "王胜龙" => "[email protected]" }

s.source  = { :git => "https://github.com/wangshenglong/SLColor.git", :tag => "#{s.version}" }

s.description = 'UIColor 的扩展'

s.source_files = 'SLColor/Classes/**/*'

s.framework    = 'QuartzCore'

# s.resources    = 'SLColor/Assets/**/*.{png,jpg}'

s.requires_arc = true

end

6、上传git(如下图)

Cocoapods创建库_第2张图片

7、验证podspec

本地:pod lib lint SLColor.podspec

远程:pod spec lint SLColor.podspec

如下报错的话按照提示运行一下

wangsheongdeMBP:SLColor long$ pod lib lint SLColor.podspec

-> SLColor (0.0.1)

- WARN  | description: The description is equal to the summary.

[!] SLColor did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it).

[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:

`echo "2.3" > .swift-version`.

You can use the `--no-clean` option to inspect any issue.

wangsheongdeMBP:SLColor long$ echo "2.3" > .swift-version

8、trunk push podspec文件

pod trunk push SLColor.podspec

成功如下:


Cocoapods创建库_第3张图片

9、下面我们新建一个SLColorDemo的项目,创建podfile,使用SLColor

platform :ios, '8.0'

def pods

pod 'SLColor'

end

target 'SLColorDemo'  do

pods

end


Cocoapods创建库_第4张图片

在ViewController中导入:

#import "UIColor+SLColor.h"

创建一个label:

UILabel *label = [[UILabel alloc] initWithFrame:self.view.frame];

label.textAlignment = NSTextAlignmentCenter;

label.textColor = [UIColor colorWithHexString:@"4a8fe2" alpha:1];

label.font = [UIFont systemFontOfSize:22];

label.text = @"可以使用么?颜色";

[self.view addSubview:label];

运行效果:


Cocoapods创建库_第5张图片

参考:1、www.jianshu.com/p/e5209ac6ce6b

            2、www.cocoachina.com/game/20170426/19131.html

你可能感兴趣的:(Cocoapods创建库)