Automatic creation based on pod: developing a static library

Source: Internet
Author: User

Reference: 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. Execute command pod lib create Trapezoidbutton. The following 5 questions need to be identified during this period .

What language does want to use?? [SWIFT/OBJC]

ObjC

would provide a demo application with your library? [Yes/no]

Yes

Which testing frameworks would you use? [Specta/kiwi/none]

Kiwi

Would do view based testing? [Yes/no]

No

What is your class prefix?

Bz

The first one is the language, the second question asks whether to provide a Demo items, usually selected Yes, others can be selected as needed. When the command finishes, it creates A basic class library framework that good one manages dependencies through Cocoapods.

2. Open the Trapezoidbutton.podspec file, modify the class library configuration information, and the result is like this.

Pod::spec.new do |s|

S.name = ' Trapezoidbutton '

s.version = ' 0.1.0 '

S.summary = ' Custom Ladder button '

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

# * Think:what does it do? Why does 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

Custom Keystone button can be clicked, change color when clicked

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 ' = ' [email protected] '}

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

By default, the source files for the class library are located under the Pod/classes folder, where the resource files are located under the Pod/assets folder, and you can modify s.source_files and s.resource_bundles to replace the storage directory. The s.public_header_files is used to specify the search location for the header file.

S.frameworks and S.libraries Specify the framework and class libraries in the dependent SDK, and it is important to note that dependencies not only include the dependencies of your own class libraries, but also the dependencies of all third-party class libraries . This is the only way to make other projects work when your class library is packaged as a. A or. Framework

The source files used in example are placed under the Pod/classes folder

3. go to the Example folder, perform pod installand let the demo The project installs the dependencies and updates the configuration.

4. Add the code. Because it is an example, only the two trapezoidal buttons are displayed simply.

Run pod install to have the demo program load the newly created class. You may have discovered that if you add a new class / resource file or a dependent three-party library, you will need to rerun the Pod install to apply the update .

The test is called in the demo project.

#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:@ "team about the war" 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:@ "Wild Ball Entertainment" 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. Submit a local code library to a git server

The directory created by Cocoapods itself is under local git management, and all we need to do is add a remote repository to GitHub or another Git service provider to create a private repository, get an SSH address, Then CD to the Trapezoidbutton directory

$ git Add.

$ git commit-s-M "Initial commit of the Library"

$ git Remote add origin [email protected]:wtlucky/podtestlibrary.git #添加远端仓库

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

5.Trapezoidbutton.podspec upload to Cocoapods's official warehouse.

(1.) before you start to submit the project to Cocoapods, did the little friends think about how to mark your source code before submitting it to you, we always want a similar account of the East Bar. Sure, then let's start with an account:

Pod trunk register [email protected] ' Pluto Y '--description= ' My own computer '

(2.) need to verify your code is wrong and Podspec file, then this time the following command will play a very big role:

Pod Lib Lint Name.podspec

(3) Verification success, upload

Pod Trunk push project name. Podspec

Automatic creation based on pod: developing a static library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.