Gowhich

Durban's Blog

我的总结是这样的:

  1. 获取控制器名
1
$this->controller = Yii::app()->controller->id;
  1. 获取动作名
1
$this->action = Yii::app()->controller->action->id;

参考的原文是这样的:

  1. 获取控制器名

在控制器中获取控制器名:

$name = $this->getId();

在视图中获取控制器名:

$name = Yii::app()->controller->id;

  1. 获取动作名

在控制器beforeAction()回调函数中获取动作名:

$name = $action->id;

在其他地方获取动作名:

$name = $this->getAction()->getId();

我试过几个,有几个不是很好用,但是我的总结里面是绝对可以使用的,因为是一个全局变量。

写描述方法:

正确的方法是子类化UIToolbar,设置其backgroundColor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@interface TranslucentToolbar : UIToolbar  

@end

@implementation TranslucentToolbar

- (void)drawRect:(CGRect)rect {
// do nothing
}

- (id)initWithFrame:(CGRect)aRect {
if ((self = [super initWithFrame:aRect])) {
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
self.clearsContextBeforeDrawing = YES;
}
return self;
}
@end

在需要创建的地方使用子类化的UIToolbar

如果你说不知道这些代码放在哪里。好吧我告诉你,其实这个就在自定义的UIoolbar中,如果你还不知道的话,请联系我好了,或者留言

安装express之后访问http://localhost:8080

会出现500 Error: Cannot find module ‘jade’错误

解决方案:
确定package.json里有添加相应的jade依赖配置

使用npm install -d 可以自动配置package.json,并安装所有需要依赖的包

命令行下执行:

1
npm install -d

用于执行一般的文件系统操作 (reading and writing is done via NSData, et. al.).

主要功能包括:

从一个文件中读取数据;

向一个文件中写入数据;

删除文件;

复制文件;

移动文件;

比较两个文件的内容;

测试文件的存在性;

读取/更改文件的属性… …

Just alloc/init an instance and start performing operations. Thread safe.

常见的NSFileManager处理文件的方法如下:

NSFileManager *fileManager = [[NSFileManager alloc]init]; //最好不要用defaultManager。
NSData *myData = [fileManager contentsAtPath:path]; // 从一个文件中读取数据
[fileManager createFileAtPath:path contents:myData attributes:dict];//向一个文件中写入数据,属性字典允许你制定要创建
[fileManager removeItemAtPath:path error:err];
[fileManager moveItemAtPath:path toPath:path2 error:err];
[fileManager copyItemAtPath:path toPath:path2 error:err];
[fileManager contentsEqualAtPath:path andPath:path2];
[fileManager fileExistsAtPath:path]; … …

常见的NSFileManager处理目录的方法如下:

[fileManager currentDirectoryPath];
[fileManager changeCurrentDirectoryPath:path];
[fileManager copyItemAtPath:path toPath:path2 error:err];
[fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:err];
[fileManager fileExistsAtPath:path isDirectory:YES];
[fileManager enumeratorAtPath:path]; //获取目录的内容列表。一次可以枚举指定目录中的每个文件。 … …
Has a delegate with lots of “should” methods (to do an operation or proceed after an error).
And plenty more. Check out the documentation.

1、文件的创建

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-(IBAction) CreateFile{

//对于错误信息

NSError *error;

// 创建文件管理器

NSFileManager *fileMgr = [NSFileManager defaultManager];

//指向文件目录

NSString *documentsDirectory= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];


//创建一个目录

[[NSFileManager defaultManager] createDirectoryAtPath: [NSString stringWithFormat:@"%@/myFolder", NSHomeDirectory()] attributes:nil];

// File we want to create in the documents directory我们想要创建的文件将会出现在文件目录中

// Result is: /Documents/file1.txt结果为:/Documents/file1.txt

NSString *filePath= [documentsDirectory

stringByAppendingPathComponent:@"file2.txt"];

//需要写入的字符串

NSString *str= @"iPhoneDeveloper Tips\nhttp://iPhoneDevelopTips,com";

//写入文件

[str writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error];

//显示文件目录的内容

NSLog(@"Documentsdirectory: %@",[fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
}

2、对文件重命名

对一个文件重命名,想要重命名一个文件,我们需要把文件移到一个新的路径下。下面的代码创建了我们所期望的目标文件的路径,然后请求移动文件以及在移动之后显示文件目录。

1
2
3
4
5
6
7
8
9
//通过移动该文件对文件重命名
NSString *filePath2= [documentsDirectory
stringByAppendingPathComponent:@"file2.txt"];
//判断是否移动
if ([fileMgr moveItemAtPath:filePath toPath:filePath2 error:&error] != YES)
NSLog(@"Unable to move file: %@", [error localizedDescription]);
//显示文件目录的内容
NSLog(@"Documentsdirectory: %@",
[fileMgr contentsOfDirectoryAtPath:documentsDirectoryerror:&error]);

3、删除一个文件

为了使这个技巧完整,让我们再一起看下如何删除一个文件:

1
2
3
4
5
6
//在filePath2中判断是否删除这个文件
if ([fileMgr removeItemAtPath:filePath2 error:&error] != YES)
NSLog(@"Unable to delete file: %@", [error localizedDescription]);
//显示文件目录的内容
NSLog(@"Documentsdirectory: %@",
[fileMgr contentsOfDirectoryAtPath:documentsDirectoryerror:&error]);

一旦文件被删除了,正如你所预料的那样,文件目录就会被自动清空:
这些示例能教你的,仅仅只是文件处理上的一些皮毛。想要获得更全面、详细的讲解,你就需要掌握NSFileManager文件的知识。

4、删除目录下所有文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//获取文件路径
- (NSString *)attchmentFolder{

NSString *document = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *path = [document stringByAppendingPathComponent:@"Attchments"];


NSFileManager *manager = [NSFileManager defaultManager];


if(![manager contentsOfDirectoryAtPath:path error:nil]){

[manager createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:nil];

}
return path;

}

–清除附件

1
BOOL result = [[NSFileManager defaultManager] removeItemAtPath:[[MOPAppDelegate instance] attchmentFolder] error:nil];

5、判断文件是否存在

1
2
3
4
5
6
7
8
9
10
11
12
NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager]fileExistsAtPath:filePath])

//do some thing


-(NSString *)dataFilePath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
return [documentDirectory stringByAppendingPathComponent:@"data.plist"];
}

常用路径工具函数

1
2
3
4
5
NSString * NSUserName(); 返回当前用户的登录名 
NSString * NSFullUserName(); 返回当前用户的完整用户名
NSString * NSHomeDirectory(); 返回当前用户主目录的路径
NSString * NSHomeDirectoryForUser(); 返回用户user的主目录
NSString * NSTemporaryDirectory(); 返回可用于创建临时文件的路径目录

常用路径工具方法

1
2
3
4
5
6
7
8
9
10
11
-(NSString *) pathWithComponents:components    根据components(NSArray对象)中元素构造有效路径 
-(NSArray *)pathComponents 析构路径,获取路径的各个部分
-(NSString *)lastPathComponent 提取路径的最后一个组成部分
-(NSString *)pathExtension 路径扩展名
-(NSString *)stringByAppendingPathComponent:path 将path添加到现有路径末尾
-(NSString *)stringByAppendingPathExtension:ext 将拓展名添加的路径最后一个组成部分
-(NSString *)stringByDeletingPathComponent 删除路径的最后一个部分
-(NSString *)stringByDeletingPathExtension 删除路径的最后一个部分 的扩展名
-(NSString *)stringByExpandingTildeInPath 将路径中的代字符扩展成用户主目录(~)或指定用户主目录(~user)
-(NSString *)stringByResolvingSymlinksInPath 尝试解析路径中的符号链接
-(NSString *)stringByStandardizingPath 通过尝试解析~、..、.、和符号链接来标准化路径

使用路径NSPathUtilities.h

1
2
3
4
5
6
7
tempdir = NSTemporaryDirectory(); 临时文件的目录名 
path = [fm currentDirectoryPath];
[path lastPathComponent]; 从路径中提取最后一个文件名
fullpath = [path stringByAppendingPathComponent:fname];将文件名附加到路劲的末尾
extenson = [fullpath pathExtension]; 路径名的文件扩展名
homedir = NSHomeDirectory();用户的主目录
component = [homedir pathComponents]; 路径的每个部分

NSProcessInfo类:允许你设置或检索正在运行的应用程序的各种类型信息

1
2
3
4
5
6
7
8
9
10
11
NSProcessInfo *)processInfo                                  返回当前进程的信息
-(NSArray*)arguments 以NSString对象数字的形式返回当前进程的参数
-(NSDictionary *)environment 返回变量/值对词典。描述当前的环境变量
-(int)processIdentity 返回进程标识
-(NSString *)processName 返回进程名称
-(NSString *)globallyUniqueString 每次调用该方法都会返回不同的单值字符串,可以用这个字符串生成单值临时文件名
-(NSString *)hostname 返回主机系统的名称
-(unsigned int)operatingSystem 返回表示操作系统的数字
-(NSString *)operatingSystemName 返回操作系统名称
-(NSString *)operatingSystemVersionString 返回操作系统当前版本
-(void)setProcessName:(NSString *)name 将当前进程名称设置为name

NSFileHandle类允许更有效地使用文件。

可以实现如下功能:

1、打开一个文件,执行读、写或更新(读写)操作;

2、在文件中查找指定位置;

3、从文件中读取特定数目的字节,或将特定数目的字节写入文件中

另外,NSFileHandle类提供的方法也可以用于各种设备或套接字。一般而言,我们处理文件时都要经历以下三个步骤:

1、打开文件,获取一个NSFileHandle对象(以便在后面的I/O操作中引用该文件)。

2、对打开文件执行I/O操作。

3、关闭文件。

1
2
3
4
5
6
7
8
NSFileHandle *fileHandle = [[NSFileHandle alloc]init]; 
fileHandle = [NSFileHandle fileHandleForReadingAtPath:path]; //打开一个文件准备读取
fileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:path];
fileData = [fileHandle availableData]; // 从设备或者通道返回可用的数据
fileData = [fileHandle readDataToEndOfFile];
[fileHandle writeData:fileData]; //将NSData数据写入文件
[fileHandle closeFile]; //关闭文件 ... ...

注:NSFileHandle类没有提供创建文件的功能,所以必须使用NSFileManager来创建文件

参考:http://blog.csdn.net/zhuzhihai1988/article/details/7904333

最近搞数据展示,需要将数字展示为用千分号分割的字符串,让我好找呀,结果还是被我找到了。

在iOS中我们可以通过NSDateFormatter来设置输出NSDate的格式。相比NSDateFormatter的大名鼎鼎,NSNumberFormatter好像知道的人就不多了。其实通过NSNumberFormatter,同样可以设置NSNumber输出的格式。例如如下代码:

1
2
3
4
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = NSNumberFormatterDecimalStyle;
NSString *string = [formatter stringFromNumber:[NSNumber numberWithInt:123456789]];
NSLog(@"Formatted number string:%@",string);

输出结果为:[1223:403] Formatted number string:123,456,789

其中NSNumberFormatter类有个属性numberStyle,它是一个枚举型,设置不同的值可以输出不同的数字格式。该枚举包括:
enum {
NSNumberFormatterNoStyle = kCFNumberFormatterNoStyle,
NSNumberFormatterDecimalStyle = kCFNumberFormatterDecimalStyle,
NSNumberFormatterCurrencyStyle = kCFNumberFormatterCurrencyStyle,
NSNumberFormatterPercentStyle = kCFNumberFormatterPercentStyle,
NSNumberFormatterScientificStyle = kCFNumberFormatterScientificStyle,
NSNumberFormatterSpellOutStyle = kCFNumberFormatterSpellOutStyle
};
typedef NSUInteger NSNumberFormatterStyle;

各个枚举对应输出数字格式的效果如下:

1
2
3
4
5
6
[1243:403] Formatted number string:123456789
[1243:403] Formatted number string:123,456,789
[1243:403] Formatted number string:¥123,456,789.00
[1243:403] Formatted number string:-539,222,988%
[1243:403] Formatted number string:1.23456789E8
[1243:403] Formatted number string:一亿二千三百四十五万六千七百八十九

其中第三项和最后一项的输出会根据系统设置的语言区域的不同而不同。

一直想搞明白nonatomic和atomic的区别,由于时间的问题一直没有去合理的看一下,最近搜索资料无意间被自己发现了,简答的记录一下

atomic的意思就是setter/getter这两个函数的一个原语操作。如果有多个线程同时调用setter的话,不会出现某一个线程执行setter全部语句之前,另一个线程开始执行setter情况,相当于函数头尾加了锁一样。 nonatomic不保证setter/getter的原语行,所以你可能会取到不完整的东西。 比如setter函数里面改变两个成员变量,如果你用nonatomic的话,getter可能会取到只更改了其中一个变量时候的状态。 atomic是线程安全的,nonatomic是线程不安全的。如果只是单线程操作的话用nonatomic最好,因为后者效率高一些。

上面是引用自参考资料的

我的理解就是,为了追求获取变量值的安全性的话就使用atomic,如果追求效率而不是安全性的话就是使用nonatomic

参考:http://blog.csdn.net/wenwei19861106/article/details/8959483

struct结构体中的数据不能赋初值,所以赋值只能通过声明加入的方式。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#import <Foundation/Foundation.h>
enum sex{
male=0,
female=1
};
typedef enum{
c=3,
d=4
}test2;
struct student {
char* name;
enum sex sex;
int age;
};
typedef struct student stu;
int main(int argc, const char * argv[])
{
stu su;
su.name="wen";
su.sex=male;
NSLog(@"name=%s,sex=%d",su.name,su.sex);
@autoreleasepool {

// insert code here...
NSLog(@"Hello, World!");

}
return 0;
}

参考:http://blog.csdn.net/wenwei19861106/article/details/8958800

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//手机序列号
NSString* identifierNumber = [[UIDevice currentDevice] uniqueIdentifier];
NSLog(@"手机序列号: %@",identifierNumber);
//手机别名: 用户定义的名称
NSString* userPhoneName = [[UIDevice currentDevice] name];
NSLog(@"手机别名: %@", userPhoneName);
//设备名称
NSString* deviceName = [[UIDevice currentDevice] systemName];
NSLog(@"设备名称: %@",deviceName );
//手机系统版本
NSString* phoneVersion = [[UIDevice currentDevice] systemVersion];
NSLog(@"手机系统版本: %@", phoneVersion);
//手机型号
NSString* phoneModel = [[UIDevice currentDevice] model];
NSLog(@"手机型号: %@",phoneModel );
//地方型号 (国际化区域名称)
NSString* localPhoneModel = [[UIDevice currentDevice] localizedModel];
NSLog(@"国际化区域名称: %@",localPhoneModel );

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
// 当前应用名称
NSString *appCurName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
NSLog(@"当前应用名称:%@",appCurName);
// 当前应用软件版本 比如:1.0.1
NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSLog(@"当前应用软件版本:%@",appCurVersion);
// 当前应用版本号码 int类型
NSString *appCurVersionNum = [infoDictionary objectForKey:@"CFBundleVersion"];
NSLog(@"当前应用版本号码:%@",appCurVersionNum);

输入的结果:

1
2
3
4
5
6
7
8
9
2013-06-27 18:08:30.608 xx[21014:c07] 手机序列号: ef4dd99784b05114b4d894964599892c00000000
2013-06-27 18:08:30.610 xx[21014:c07] 手机别名: iPhone Simulator
2013-06-27 18:08:30.610 xx[21014:c07] 设备名称: iPhone OS
2013-06-27 18:08:30.611 xx[21014:c07] 手机系统版本: 6.1
2013-06-27 18:08:30.612 xx[21014:c07] 手机型号: iPhone Simulator
2013-06-27 18:08:30.612 xx[21014:c07] 国际化区域名称: iPhone Simulator
2013-06-27 18:08:30.613 xx[21014:c07] 当前应用名称:寻艺
2013-06-27 18:08:30.614 xx[21014:c07] 当前应用软件版本:1.0
2013-06-27 18:08:30.614 xx[21014:c07] 当前应用版本号码:1

查资料的时候无意间发现了一个很好玩的:

代码段:[[UIApplication sharedApplication] openURL:url];

其中系统的url有:

1.Map http://maps.google.com/maps?q=Shanghai

2.Email mailto://[email protected]

3.Tel tel://10086

4.Msg sms://10086

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
- (IBAction)openMaps {
//打开地图
NSString*addressText = @"beijing";
//@"1Infinite Loop, Cupertino, CA 95014";
addressText =[addressText stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

NSString *urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@",addressText];
NSLog(@"urlText=============== %@", urlText);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
}

- (IBAction)openEmail {
//打开mail // Fire off an email to apple support
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"mailto://[email protected]"]];
}

- (IBAction)openPhone {

//拨打电话
// Call Google 411
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];
}

- (IBAction)openSms {
//打开短信
// Text toGoogle SMS
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://10086"]];
}

-(IBAction)openBrowser {
//打开浏览器
// Lanuch any iPhone developers fav site
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://blog.csdn.net/duxinfeng2010"]];
}

参考资料:http://blog.csdn.net/duxinfeng2010/article/details/8176317

直接上代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// TWFXToolBarViewController.m
// DemoToolBar
//
// Created by Lion User on 13-1-19.
// Copyright (c) 2013年 Lion User. All rights reserved.
//

#import "TWFXToolBarViewController.h"

@interface TWFXToolBarViewController ()

@end

@implementation TWFXToolBarViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization

//创建toolbar
UIToolbar *toolBar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 420.0f, 320.0f, 40.0f) ] autorelease];

//创建barbuttonitem
UIBarButtonItem *item1 = [[[UIBarButtonItem alloc] initWithTitle:@"收藏" style:UIBarButtonItemStyleBordered target:self action:@selector(test:)] autorelease];

//创建barbuttonitem
UIBarButtonItem *item2 = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:nil] autorelease];

//创建一个segmentController
UISegmentedControl *seg = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"牛扒", @"排骨", nil] ] autorelease];

//设置style
[seg setSegmentedControlStyle:UISegmentedControlSegmentCenter];


[seg addTarget:self action:@selector(segmentControllerItem:) forControlEvents:UIControlEventValueChanged];

//创建一个内容是view的uibarbuttonitem
UIBarButtonItem *itemSeg = [[[UIBarButtonItem alloc] initWithCustomView:seg] autorelease];

//创建barbuttonitem,样式是flexible,这个种barbuttonitem用于两个barbuttonitem之间
//调整两个item之间的距离.flexible表示距离是动态的,fixed表示是固定的
UIBarButtonItem *flexible = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil] autorelease];

//把item添加到toolbar里
[toolBar setItems:[NSArray arrayWithObjects:item1,flexible,itemSeg,flexible,item2, nil] animated:YES];

//把toolbar添加到view上
[self.view addSubview:toolBar];

}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}

-(void)test:(id)sender
{
UIBarButtonItem *item = (UIBarButtonItem *) sender;
NSString *title = [NSString stringWithFormat:@"%@ 被选中了",item.title];

UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Attention" message:title delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil] autorelease];

[alertView show];
}


-(void)segmentControllerItem:(id)sender
{
UISegmentedControl *seg = (UISegmentedControl *) sender;
NSInteger index = seg.selectedSegmentIndex;
NSString *message;
if (index == 0) {
message = @"你选了牛扒";
}
else
{
message = @"你选了排骨";
}

UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Attenton" message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease];

[alertView show];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)goBack:(UIButton *)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end

自己实践测试过了。效果很不错,在我之前做的和现在比的话,关键一点是“[toolBar setItems:[NSArray arrayWithObjects:item1,flexible,itemSeg,flexible,item2, nil] animated:YES];”这里很重要,使得自己不用去通过CGRectMake来设置。

也许你有个问题是我想使用UIButton,好的你跟我的想法是一样的,我贴一帖我的代码好了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-(void) showEditBar{
//创建toolbar
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat toolbarWidth = 200.0;
CGFloat toolbarHeight = 45.0;
CGFloat toolbarMarginBottom = 10.0;
CGFloat toolbarX = (screenRect.size.width - toolbarWidth) / 2;
CGFloat toolbarY = (screenRect.size.height - toolbarMarginBottom - toolbarHeight) - 2 * 44.0 - 22.0;

_editToolBar = [[DeleteToolBar alloc] initWithFrame:CGRectMake(toolbarX, toolbarY, toolbarWidth, toolbarHeight)];
_editToolBar.barStyle = UIBarStyleDefault;
_editToolBar.translucent = YES;

UIButton *deleteBar = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, toolbarWidth/2, _editToolBar.frame.size.height)];
deleteBar.titleLabel.font = [UIFont systemFontOfSize:24.0];
deleteBar.layer.backgroundColor = [[ColorConfig NavigationColor] CGColor];
deleteBar.layer.borderWidth = 2.0;
deleteBar.layer.borderColor = [[ColorConfig NavigationColor] CGColor];
deleteBar.layer.cornerRadius = 10.0;
deleteBar.alpha = 1.0;

[deleteBar setTitle:@"删除" forState:UIControlStateNormal];
[deleteBar addTarget:self action:@selector(deleteAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *deleteBarBtn = [[UIBarButtonItem alloc] initWithCustomView:deleteBar];

//创建barbuttonitem,样式是flexible,这个种barbuttonitem用于两个barbuttonitem之间
//调整两个item之间的距离.flexible表示距离是动态的,fixed表示是固定的
UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

//把item添加到toolbar里
[_editToolBar setItems:[NSArray arrayWithObjects:flexible,deleteBarBtn,flexible, nil] animated:YES];

//把toolbar添加到view上
[self.view addSubview:_editToolBar];

//设置table的位置
[self.dataTable setFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, TABLE_VIEW_HEIGHT - COMPARE_BAR_HEIGHT - 8.0)];
}

参考文章:http://www.cnblogs.com/zouzf/archive/2013/01/19/2867574.html

0%