"iOS development-13" big artifact: How to use cocoapods third-party class library for Uiswitch third-party class library as an example

Source: Internet
Author: User
Tags border color

The previous note and some of the previous notes have some properties that have no effect, such as the switch background image of the uiswitch switch control, or simply do not have the attributes we want, such as setting the control size directly from the code.


Therefore, we need to use a third-party class library, which means that we do not use the Uiswitch class to instantiate an object, but rather a third-party class to instantiate an object, and then this object can be modified arbitrarily.


The logic here, of course, is that we're going to import a third-party class library, maybe we need to introduce it into the header file, and then we can instantiate it, but how do we use a third-party class library? Cocoapods artifact.


The installation and use tutorials are as follows: Click here (quite complete)


(1) Gem is a software management command in the Ruby environment, similar to the Linux yum, so Yum installs under Linux, so this is the gem install.


(2) But gem install when it went to find the source program was "wall", so we need to convert the gem source to a domestic http://ruby.taobao.org/, when we go to this site, it also has a tutorial to teach you how to change the gem source, But its official tutorial inside is HTTPS, according to the official HTTPS words will appear to find this site, with http found normal, we suggest you still use the above tutorial http.


(3) We found a third-party class library for Uiswitch, which is basically on GitHub, Bvogelzang teacher's sevenswitch when used here. Use pod search Sevenswitch (the case is not divided) can be searched.


(4) found on the installation of Bai, the installation is actually in the project directory to create a podfile, in which we need to install the file and version, and so on. This project directory is when we create this project, choose the saved path, not in "iOS development 3" in the sandbox inside the program path.


(5) First according to Bvogelzang Teacher's document write ' ~> 2.0 ', and then pod install found this file, we used pod search Sevenswith found this file is 1.4.0 version, we try to continue vim Podfile change the inside to ' ~> 1.4.0 ' and run pod install successfully.


(6) Then open the file with the. xcworkspace suffix that it prompts, the name or our project name, we can open our project directory so that we can clearly see what has changed (several new files are added).


(7) Introduce the SevenSwit.h header file in our common VIEWCONTROLLER.M file so that we can instantiate the object and customize it wildly.


(8) over. Learn how to use a third-party class library for iOS development knowledge.


The code is as follows:

#import "ViewController.h"//Introduce header file to #import "SevenSwitch.h" @interface Viewcontroller () @end @implementation    viewcontroller-(void) Viewdidload {//Initialize an object with Sevenswitch Sevenswitch *swi3=[[sevenswitch Alloc]init];    The switch size can be set, that is, the high width setting has the effect of Swi3.frame=cgrectmake (30, 30, 100, 40);    Set the background picture of open, close and slide, effectively swi3.onimage=[uiimage imagenamed:@ "1.png";    Swi3.offimage=[uiimage imagenamed:@ "3.png"];    Swi3.thumbimage=[uiimage imagenamed:@ "Small.png"];    Set the text of the switch, the official time on and off [email protected] "on";    [email protected] "off";    Turning the fillet angle into a square switch swi3.isrounded=false;    The original attribute is used as usual, as set by default to On [Swi3 Seton:yes];    Set the border color, can be seen when off, because it is the default green background Swi3.bordercolor=[uicolor Purplecolor];    Of course there are active and inactive colors, this temporarily do not know how to use, but it is very rich, there are wood swi3.activecolor=[uicolor graycolor];    Swi3.inactivecolor=[uicolor Redcolor];    Of course, do not forget that it can still be used operation [Swi3 addtarget:self action: @selector (getValue1:) forcontrolevents:uicontroleventvaluechanged];    [Self.view Addsubview:swi3]; [SupeR Viewdidload]; Do any additional setup after loading the view, typically from a nib.} @end

Screenshot of the effect:


"iOS development-13" big artifact: How to use cocoapods third-party class library for Uiswitch third-party class library as an example

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.