奇数项UIBarButtonItem在UIToolbar 中的居中对齐 - 有只茄子
2012-5-3 10:30:0 Author: www.cnblogs.com(查看原文) 阅读量:2 收藏

 1 toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
 2 
 3 toolBar.barStyle = UIBarStyleDefault;
 4 
 5  
 6 
 7 UIBarButtonItem *titleButton = [[UIBarButtonItem alloc] initWithTitle:title 
 8 
 9                                                                         style: UIBarButtonItemStylePlain 
10 
11                                                                        target: nil 
12 
13                                                                        action: nil];
14 
15         
16 
17 UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"完成" 
18 
19                                                                         style: UIBarButtonItemStyleDone 
20 
21                                                                        target: self 
22 
23                                                                        action: @selector(done)];
24 
25         
26 
27 //UIBarButtonItem *leftButton  = [[UIBarButtonItem alloc] initWithTitle:@"取消" 
28 
29 //                                                                        style: UIBarButtonItemStyleBordered 
30 
31 //                                                                       target: self 
32 
33 //                                                                       action: @selector(docancel)];
34 
35         
36 
37 UIBarButtonItem *fixedButton  = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace 
38 
39                                                                                       target: nil 
40 
41                                                                                       action: nil];
42 
43         
44 
45 NSArray *array = [[NSArray alloc] initWithObjects:fixedButton,fixedButton, titleButton,fixedButton, rightButton, nil];
46 
47 [toolBar setItems: array];
48 
49 [titleButton release];
50 
51 //[leftButton  release];
52 
53 [rightButton release];
54 
55 [fixedButton release];
56 
57 [array       release];

对齐通过填充FlexibleSpace来实现。


文章来源: https://www.cnblogs.com/qiezi/archive/2012/05/03/2480191.html
如有侵权请联系:admin#unsafe.sh