Li Hongqiang a static library of iOS development

Source: Internet
Author: User

Li Hongqiang a static library of IOS development

static libraries generally do a few things

//1 Tool class algorithm logic

New Tool Class Lhqtools

Defining class methods

+ (nsinteger) sumWithNum1: (nsinteger) num1 andNum2: (nsinteger) num2;

Implementation of class methods

+ (nsinteger) sumWithNum1: (nsinteger) num1 andNum2: (nsinteger) num2{

return num1 + num2;

}

Use

Calculate the value on the host controller

NSLog(@ "%ld", (long) [lhqtools sumWithNum1:ten andNum2 :]);

2 implement load a certain resource , put in the bundle to avoid The name of the resource

Drag the bundle that holds the picture into the folder

Defining class methods

+ (UIImage *) Loadlogo;

Implementing a class method

+ (UIImage *) loadlogo{

// wrap the picture in the bundle

return [UIImage imagenamed:@ "Cztools.bundle/logo.png"];

}

Come to the master controller to use

Uiimageview *imageview1 = [[uiimageview alloc]initwithframe:cgrectmake( [+ ];

ImageView1. image = [lhqtools Loadlogo];

[self. View addsubview: imageView1];

This time, running the program, will show this picture

//3 Package View

To create a new class that inherits from UIView

Defining class methods

#import <UIKit/UIKit.h>

@interface lhqdemoview: UIView

-(instancetype) initWithFrame: (cgrect) frame andcompelete: (void(^) (nsstring *msg)) Block;

@end

Implementing a class method

#import "LHQDemoView.h"

@interface lhqdemoview()

You must use copy when defining the block.

/*

Block default in stack stack memory System Management

System Management has a disadvantage : to the end of action to be killed

after performing a copy operation , the block is placed from the stack into the heap

will automatically have a strong reference to point to it

*/

@property(nonatomic,copy)void(^block) (nsstring *);

@end

@implementation Lhqdemoview

-(instancetype) initWithFrame: (cgrect) frame andcompelete: (void(^) (nsstring *msg)) block{

if(self = [super initwithframe: frame]) {

UIButton *btn = [[UIButton alloc]initwithframe:cgrectmake(0, 0, (+ )];

[Btn settitle:@ " hint " forstate:uicontrolstatenormal];

[Btn addTarget:self action:@selector(btnclicked:) forcontrolevents:uicontroleventtouchupinside];

[self addsubview: btn];

self. Block = block;

}

return self ;

}

-(void) btnclicked: (UIButton *) btn{

self. Block(@ " clicked on a button ");

NSLog(@ "btnclicked");

}

-(void) DrawRect: (cgrect) rect{

// draw a circle

uibezierpath *path = [uibezierpath bezierpathwithovalinrect:self. Bounds];

[[uicolor redcolor]setfill];

[Path stroke];

[Path fill];

}

Come to the host controller called:

3 Package View

    lhqdemoview *demoview = [[lhqdemoview alloc]initwithframe:cgrectmake (100200100100 andcompelete:^ (nsstring * msg) {

        uialertview *alert = [[ Span class= "S7" >uialertview alloc] Initwithtitle:@ " warm hint " Span class= "S1" >message:msg delegate:nil< Span class= "S8" > cancelbuttontitle:@ " Cancel Span class= "S9" > " otherbuttontitles:nil< Span class= "S8", nil];

[Alert show];

}];

[self. View addsubview:d Emoview];

Effect:

Li Hongqiang a static library of iOS development

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.