iOS 静态度制作方法详细

本文详细介绍了如何在iOS开发环境中创建并使用静态库。通过六个步骤,从创建静态库项目开始,逐步指导如何实现库的功能,并在另一个项目中导入及使用该静态库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

按照步骤和我一起来:

第一步:创建一个新的工程,选择Framework,然后选择cocoa Touch Static Libarary ,添加你自己想要的名字ok,这里我取为“myLibrary”


第二步:在myLibrary.h中添加并改为

[html]  view plain copy
  1. #import <Foundation/Foundation.h>  
  2.    
  3. #import <UIKit/UIKit.h>  
  4.    
  5. @interface myLibrary : NSObject  
  6.    
  7. -(void)testFunction;  
  8.    
  9. @end  

第三步:在myLibrary.m中改为

[html]  view plain copy
  1. #import "myLibrary.h"  
  2.    
  3.    
  4.    
  5. @implementation myLibrary  
  6.    
  7. -(void)testFunction{  
  8.    
  9. UIAlertView *myAlert=[[UIAlertView alloc] initWithTitle:@"哈哈,这个是静态库!"  
  10.    
  11. message:@"成功了!"  
  12.    
  13. delegate:self  
  14.    
  15. cancelButtonTitle:@"取消"  
  16.    
  17. otherButtonTitles:nil, nil];  
  18.    
  19. [myAlert show];  
  20.    
  21. [myAlert release];  
  22.    
  23. }  
  24.    
  25. @end  
第四步:在左上角选择中改为iphone simulator


第五步:Bulid  & Run ,会在Bulid文件夹里面有个libmyLibrary.a的文件

第六步:新建工程testLibrary


第七步:导入生成的libmyLibrary.a静态库和头文件,可以直接拖入到工程


第八步:在testLibrary 工程的

“ViewController.m”文件的viewDidLoad方法中添加

[html]  view plain copy
  1. #import "ViewController.h"  
  2.    
  3. #import "myLibrary.h"  
  4.    
  5. @interface ViewController ()  
  6.    
  7. @end  
  8.    
  9. @implementation ViewController  
  10.    
  11. - (void)viewDidLoad  
  12.    
  13. {  
  14.    
  15. [super viewDidLoad];  
  16.    
  17. // Do any additional setup after loading the view, typically from a nib.  
  18.    
  19. myLibrary* pp=[[myLibrary alloc] init];  
  20.    
  21. [pp testFunction];  
  22.    
  23. [pp release];  
  24.    
  25. }  

第九步:Bulid  & Run 我们的testLibrary 工程 然后九看到效果了


最后还有就是这个libmyLibrary.a静态库分为模拟器和真机的,切换也很方便就在


在这个地方切换为真机就ok了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值