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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值