按照步骤和我一起来:
第一步:创建一个新的工程,选择Framework,然后选择cocoa Touch Static Libarary ,添加你自己想要的名字ok,这里我取为“myLibrary”
第二步:在myLibrary.h中添加并改为
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface myLibrary : NSObject
-(void)testFunction;
@end
第三步:在myLibrary.m中改为
#import "myLibrary.h"
@implementation myLibrary
-(void)testFunction{
UIAlertView *myAlert=[[UIAlertView alloc] initWithTitle:@"哈哈,这个是静态库!"
message:@"成功了!"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:nil, nil];
[myAlert show];
[myAlert release];
}
@end
第四步:在左上角选择中改为iphone simulator
第五步:Bulid & Run ,会在Bulid文件夹里面有个libmyLibrary.a的文件
第六步:新建工程testLibrary
第八步:在testLibrary 工程的
“ViewController.m”文件的viewDidLoad方法中添加
#import "ViewController.h"
#import "myLibrary.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
myLibrary* pp=[[myLibrary alloc] init];
[pp testFunction];
[pp release];
}
第九步:Bulid & Run 我们的testLibrary 工程 然后九看到效果了
最后还有就是这个libmyLibrary.a静态库分为模拟器和真机的,切换也很方便就在
在这个地方切换为真机就ok了!