iPhone控制項之UIToolbar

來源:互聯網
上載者:User
 1 //
2 // UITestViewController.m
3 // UITest
4 //
5
6 #import "UITestViewController.h"
7
8 @implementation UITestViewController
9
10
11 - (void)buttonClick:(id)sender {
12
13 NSLog(@"you clicked button: %@",[sender title]);
14 }
15
16 - (void)viewDidLoad {
17
18 [super viewDidLoad];
19
20 CGSize viewSize = self.view.frame.size;
21 float toolbarHeight = 44.0;
22 CGRect toolbarFrame = CGRectMake(0,viewSize.height-toolbarHeight,viewSize.width,toolbarHeight);
23
24 UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame];
25
26 myToolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth
27 |
28 UIViewAutoresizingFlexibleLeftMargin
29 |
30 UIViewAutoresizingFlexibleRightMargin
31 |
32 UIViewAutoresizingFlexibleTopMargin;
33
34 UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithTitle:@"button 1"
35 style:UIBarButtonItemStylePlain target:self
36 action:@selector(buttonClick:)];
37
38 UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithTitle:@"button 2"
39 style:UIBarButtonItemStyleBordered
40 target:self
41 action:@selector(buttonClick:)];
42
43 UIBarButtonItem *button3 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"apple_icon.png"]
44 style:UIBarButtonItemStyleBordered
45 target:self
46 action:@selector(buttonClick:)];
47
48 UIBarButtonItem *flexButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
49 target:nil
50 action:nil];
51
52 UIBarButtonItem *trashButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash
53 target:self
54 action:@selector(buttonClick:)];
55
56 NSArray *buttons = [[NSArray alloc] initWithObjects:button1,button2,button3, flexButton,trashButton,nil];
57
58 //cleanup
59 [button1 release];
60 [button2 release];
61 [button3 release];
62 [flexButton release];
63 [trashButton release];
64
65 [myToolbar setItems:buttons animated:NO];
66
67 [buttons release];
68
69 [self.view addSubview:myToolbar];
70
71 [myToolbar release];
72 }
73
74 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
75
76 return YES;
77 }
78
79 - (void)didReceiveMemoryWarning {
80 // Releases the view if it doesn't have a superview.
81 [super didReceiveMemoryWarning];
82
83 // Release any cached data, images, etc that aren't in use.
84 }
85
86 - (void)viewDidUnload {
87 // Release any retained subviews of the main view.
88 // e.g. self.myOutlet = nil;
89 }
90
91
92 - (void)dealloc {
93 [super dealloc];
94 }
95
96 @end

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.