现在的位置: 首页 > 综合 > 正文

iOS 静态度制作方法详细

2018年05月12日 ⁄ 综合 ⁄ 共 1281字 ⁄ 字号 评论关闭

按照步骤和我一起来:

第一步:创建一个新的工程,选择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了!

抱歉!评论已关闭.