zoukankan      html  css  js  c++  java
  • 李洪强iOS开发之静态库的打包一

    李洪强iOS开发之静态库的打包一

    //静态库一般做一下几种事情

        //1 工具类 算法逻辑

     

    新建工具类LHQTools

     

    定义类方法

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

     

    类方法的实现

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

        

        return num1 + num2;

    }

     

    使用

    在主控制器计算值

     NSLog(@"%ld",(long)[LHQTools sumWithNum1:10 andNum2:10]);

     


    //2 实现加载一定的资源,放在bundle中避免资源重名

     

    将存放图片的bundle拖入文件夹

    定义类方法

    + (UIImage *)loadLogo;

    实现类方法

    +(UIImage *)loadLogo{

        //把图片封装到bundle里面

        return [UIImage imageNamed:@"CZTools.bundle/logo.png"];

    }

     

    来到主控制器中使用

    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

        imageView1.image = [LHQTools loadLogo];

        [self.view addSubview:imageView1];

     

    这个时候,运行程序,会显示这张图片

     

     

     

     

     //3 封装视图

    新建继承自UIView的类 

     

    定义类方法

    #import <UIKit/UIKit.h>

     

    @interface LHQDemoView : UIView

    - (instancetype)initWithFrame:(CGRect)frame andCompelete:(void(^)(NSString *msg))block;

    @end

     

    实现类方法

     

    #import "LHQDemoView.h"

    @interface LHQDemoView()

    //block定义的时候一定要用copy

    /*

     block默认在栈中  栈中内存归系统管理

     系统管理有个弊端:到作用于结束就被干掉

     执行了一个copy操作之后,就会把block从栈中放到堆中

     会自动有一个强引用来指向它

     

     

     */

    @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, 50, 50)];

            [btn setTitle:@"提示" forState:UIControlStateNormal];

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

            [self addSubview:btn];

            self.block = block;

        }

        return self;

    }

     

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

        self.block(@"点击了某个按钮");

        NSLog(@"btnClicked");

    }

     

    - (void)drawRect:(CGRect)rect{

        //画一个圆

        UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:self.bounds];

        [[UIColor redColor]setFill];

    //    [path stroke];

        [path fill];

    }

     

     

     

    来到主控制器中调用: 

    //3 封装视图

        LHQDemoView *demoView = [[LHQDemoView alloc]initWithFrame:CGRectMake(100, 200, 100, 100) andCompelete:^(NSString *msg) {

            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];

            [alert show];

        }];

        [self.view addSubview:demoView];

     效果: 

     

     

     

     

    //打包.a的细节

        //版本分情况

        // 真机

        //debug  调试(增加了控制台的各种输出 效率不太好)

        //realease 发布 上线 (纯净)

        //模拟器

        //debug  调试(增加了控制台的各种输出 效率不太好)

        //realease 发布 上线 (纯净)

        //合并真机和模拟器的指令,大小是两种之和

        //lipo -create

        //-output libCZTools

     为了代码的保密

    加密的(key)不想让别人看到,就封装到.a里面返回一个加密之后的字符串

    不知道盐别人是看不到的

     

  • 相关阅读:
    QT 图形视图框架
    QSting, QChar, char等的转换
    ucosii(2.89)mbox 应用要点
    ucosii(2.89)semaphore 应用要点
    ucosii(2.89)mutex 应用要点
    ucosii(2.89) 在Lpc1765移植中定时器的使用。
    c++中虚函数的需要性,虚析构函数的必要性
    转 在Qt中用QAxObject来操作Excel
    关于 QObject 类
    关于sigleton模式
  • 原文地址:https://www.cnblogs.com/LiLihongqiang/p/7086574.html
Copyright © 2011-2022 走看看