码迷,mamicode.com
首页 > 其他好文 > 详细

基于pod自动创建:开发静态库(Static Library)

时间:2016-06-17 19:26:05      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

参考:http://blog.csdn.net/youtk21ai/article/details/50750300

  http://www.cnblogs.com/brycezhang/p/4117180.html

  http://www.cocoachina.com/ios/20150228/11206.html

 

1.执行命令pod lib create TrapezoidButton。在此期间需要确认下面5个问题。

What language do you want to use?? [ Swift / ObjC ]

objc

Would you like to provide a demo application with your library? [ Yes / No ]

yes

Which testing frameworks will you use? [ Specta / Kiwi / None ]

Kiwi

Would you like to do view based testing? [ Yes / No ]

No

What is your class prefix?

BZ

第一个是语言,第二个问题询问是否提供一个demo项目,通常选择Yes,其他的可以根据需要选择。命令执行完后,就会创建好一个通过cocoapods管理依赖关系的基本类库框架。

2.打开TrapezoidButton.podspec文件,修改类库配置信息,结果像这样。

Pod::Spec.new do |s|

  s.name             = ‘TrapezoidButton‘

  s.version          = ‘0.1.0‘

  s.summary          = ‘自定义梯形button‘

 

# This description is used to generate tags and improve search results.

#   * Think: What does it do? Why did you write it? What is the focus?

#   * Try to keep it short, snappy and to the point.

#   * Write the description between the DESC delimiters below.

#   * Finally, don‘t worry about the indent, CocoaPods strips it!

 

  s.description      = <<-DESC

                        自定义梯形按钮可以点击,点击时改变颜色

                       DESC

 

  s.homepage         = ‘https://github.com/xilanglang/TrapezoidButton‘

  # s.screenshots     = ‘www.example.com/screenshots_1‘, ‘www.example.com/screenshots_2‘

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

  s.author           = { ‘caoyanan‘ => ‘2606090119@qq.com‘ }

  s.source           = { :git => ‘https://github.com/xilanglang/TrapezoidButton.git‘, :tag => s.version }

  # s.social_media_url = ‘https://twitter.com/<TWITTER_USERNAME>‘

 

  s.ios.deployment_target = ‘7.0‘

 

  s.source_files = ‘TrapezoidButton/Classes/**/*‘

 

  # s.resource_bundles = {

  #   ‘TrapezoidButton‘ => [‘TrapezoidButton/Assets/*.png‘]

  # }

 

  # s.public_header_files = ‘Pod/Classes/**/*.h‘

  # s.frameworks = ‘UIKit‘, ‘MapKit‘

  # s.dependency ‘AFNetworking‘, ‘~> 2.3‘

end

 

按照默认配置,类库的源文件将位于Pod/Classes文件夹下,资源文件位于Pod/Assets文件夹下,可以修改s.source_files和s.resource_bundles来更换存放目录。s.public_header_files用来指定头文件的搜索位置。

s.frameworks和s.libraries指定依赖的SDK中的framework和类库,需要注意,依赖项不仅要包含你自己类库的依赖,还要包括所有第三方类库的依赖,只有这样当你的类库打包成.a或.framework时才能让其他项目正常使用

 

Example中用到的源文件放到Pod/Classes文件夹下

技术分享

3.进入Example文件夹,执行pod install,让demo项目安装依赖项并更新配置。

 

4.添加代码。因为是示例,只简单显示两个梯形按钮。

 

技术分享

运行Pod install,让demo程序加载新建的类。也许你已经发现了,只要新增加类/资源文件或依赖的三方库都需要重新运行Pod install来应用更新

demo项目中调用测试。

#import "LeftTrapezoidButton.h"

#import "RightTrapezoidButton.h"

#define Bounds_w(val) ((val).bounds.size.width)

#define Bounds_h(val) ((val).bounds.size.height)

 

@interface XinViewController ()

{

    LeftTrapezoidButton *leftTrapezoidButton;

    RightTrapezoidButton *rightTrapezoidButton;

}

@end

 

@implementation XinViewController

 

- (void)viewDidLoad

{

    [super viewDidLoad];

    self.view.backgroundColor=[UIColor yellowColor];

    

    

    leftTrapezoidButton=[[LeftTrapezoidButton alloc] initWithFrame:CGRectMake(Bounds_w(self.view)/2-70, (Bounds_h(self.view)-26)/2, 86, 26)];

    [leftTrapezoidButton setTitle:@"球队约战" forState:UIControlStateNormal];

    [leftTrapezoidButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 15, 0, 30)];

    [leftTrapezoidButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    [leftTrapezoidButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];

    leftTrapezoidButton.titleLabel.font=[UIFont systemFontOfSize:10];

    [leftTrapezoidButton addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];

    leftTrapezoidButton.tag=202;

    [self.view addSubview:leftTrapezoidButton];

    leftTrapezoidButton.selected=YES;

    

    rightTrapezoidButton=[[RightTrapezoidButton alloc] initWithFrame:CGRectMake(Bounds_w(self.view)/2-4, (Bounds_h(self.view)-26)/2, 86, 26)];

    [rightTrapezoidButton setTitle:@"野球娱乐" forState:UIControlStateNormal];

    [rightTrapezoidButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 30, 0, 15)];

    [rightTrapezoidButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    [rightTrapezoidButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];

    rightTrapezoidButton.titleLabel.font=[UIFont systemFontOfSize:10];

    [rightTrapezoidButton addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];

    rightTrapezoidButton.tag=203;

    [self.view addSubview:rightTrapezoidButton];

 

}

- (void)btnClicked:(UIButton *)button{

    if(button==leftTrapezoidButton){

        leftTrapezoidButton.selected=YES;

        rightTrapezoidButton.selected=NO;

    }else if(button==rightTrapezoidButton){

        leftTrapezoidButton.selected=NO;

        rightTrapezoidButton.selected=YES;

    }

}

@end

 

4.提交本地代码库到git服务器

通过Cocoapods创建出来的目录本身就在本地的Git管理下,我们需要做的就是给它添加远端仓库,同样去GitHub或其他的Git服务提供商那里创建一个私有的仓库,拿到SSH地址,然后cd到TrapezoidButton目录

$ git add .

$ git commit -s -m "Initial Commit of Library"

$ git remote add origin git@coding.net:wtlucky/podTestLibrary.git           #添加远端仓库

$ git push origin master     #提交到远端仓库

 

5.TrapezoidButton.podspec 上传到Cocoapods官方的仓库里去

(1.)在开始提交项目到Cocoapods之前,小伙伴们有没有想过在提交源代码前怎么标示你的源代码是属于你的,我们总要一个类似账号的东东吧。当然需要,那么我们先来搞一个账号吧:

pod trunk register abc@163.com ‘Pluto Y‘ --description=‘My own computer‘

 

(2.)需要验证你的代码是否有错以及Podspec文件,那么这个时候下面这条命令就起到非常大的作用了:

pod lib lint Name.podspec

(3)验证成功,上传

pod trunk push 项目名.podspec

基于pod自动创建:开发静态库(Static Library)

标签:

原文地址:http://www.cnblogs.com/xilanglang/p/5594806.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!