【002】【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

//
//  MyAlertView.h
//  MyAlertView
//
//  Created by dagger on 14-8-14.
//  Copyright (c) 2014年 Baidu. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "UIKit/UIKit.h"
@interface MyAlertView : UIAlertView<UIAlertViewDelegate>

+(void)showMessage:(NSString*)messageString;

@end

【2】MyAlertView.m

//
//  MyAlertView.m
//  MyAlertView
//
//  Created by dagger on 14-8-14.
//  Copyright (c) 2014年 Baidu. All rights reserved.
//

#import "MyAlertView.h"

@implementation MyAlertView

+ (void)showMessage:(NSString*)messageString
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
                                                        message:messageString
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
    [alertView show];
}

@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之後可以看到使用成功的效果

發佈了28 篇原創文章 · 獲贊 5 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章