【Xcode6-Beta5】IOS静态库的制作与使用

一、制作静态库

1、创建静态库的Project

【1】File->New->Project->IOS->Framework & Library->Cocoa Touch Static Libary

【2】Product Name==>我的是MyAlertView->然后Create

【目录结构如图所示】会生成MyAlertView.h和MyAlertView.m

2、修改代码

【1】MyAlertView.h

[objc]  view plain copy
  1. //  
  2. //  MyAlertView.h  
  3. //  MyAlertView  
  4. //  
  5. //  Created by dagger on 14-8-14.  
  6. //  Copyright (c) 2014年 Baidu. All rights reserved.  
  7. //  
  8.   
  9. #import <Foundation/Foundation.h>  
  10. #import "UIKit/UIKit.h"  
  11. @interface MyAlertView : UIAlertView<UIAlertViewDelegate>  
  12.   
  13. +(void)showMessage:(NSString*)messageString;  
  14.   
  15. @end  

【2】MyAlertView.m

[objc]  view plain copy
  1. //  
  2. //  MyAlertView.m  
  3. //  MyAlertView  
  4. //  
  5. //  Created by dagger on 14-8-14.  
  6. //  Copyright (c) 2014年 Baidu. All rights reserved.  
  7. //  
  8.   
  9. #import "MyAlertView.h"  
  10.   
  11. @implementation MyAlertView  
  12.   
  13. + (void)showMessage:(NSString*)messageString  
  14. {  
  15.     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil  
  16.                                                         message:messageString  
  17.                                                        delegate:nil  
  18.                                               cancelButtonTitle:@"OK"  
  19.                                               otherButtonTitles:nil];  
  20.     [alertView show];  
  21. }  
  22.   
  23. @end  


 

3、设置Release

【1】Edit Scheme->Run->Release->Close

4、Build一下,发现Build Succeeded之后在工程目录下的Products文件夹下的静态库文件libMyAlertView.a依然为红色,右键选择【Show in Finder】也是进不去,此时我们可以单击静态库文件libMyAlertView.a会在Xcode最右边的子窗口中发现Full Path,按照完整路径我们可以找到静态库所在位置,如下图,我们在Finder下通过快捷键【command+shift+G】的方式可以输入文件路径前缀,然后一直找到静态库和对应所需的头文件

二、使用静态库

1、创建我的App的Project

【1】File->New->Project->IOS->Application->Single View Application

【2】Product Name==>我的是TestDemo->然后Create

【目录结构如图所示】

2、加入静态库

【1】向新建项目Project中添加静态库,如图,需要将include文件夹和静态库文件一并拖入到工程的TestDemo目录下

【2】在弹出框中勾选上【Copy items if needed】->【Finish】

【3】修改AppDelegate.m

    ​1)添加头文件:#import "include/MyAlertView/MyAlertView.h"

    ​2)  修改函数application(),添加如下代码[MyAlertView showMessage:@"This is a test!"];

3、Build之后可以看到使用成功的效果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值