圖片toolbar iphone

來源:互聯網
上載者:User
   

toolbars are used to present a set of functions to a user. You will see these at the bottom of iPhone apps and generally give you the option to do things like edit files, send email or take a picture. Here is an example of what a toolbar will look like in an iPhone app:

效果類似於圖片庫中的,toolbar上是圖片按鈕,並且可以分部排列.

Using UIToolbar in Your iPhone Apps

Today, I am going to show you how to use UIToolbar in your iPhone apps. Essentially, what you need to do is to create an instance of UIToolbar, add buttons to it and then add the toolbar to your view. Usually, you will also need to assign actions to each toolbar button as well.

Here is video of how to use UIToolbar taken from my own code library that I ship with my ebook:

Source Code for Using UIToolbar

#import "Toolbar.h"@implementation ToolbarUILabel *label;UIToolbar *toolbar;- (void)viewDidLoad {    [super viewDidLoad];//Create labellabel = [[UILabel alloc] init];label.frame = CGRectMake(10, 10, 300, 40);label.textAlignment = UITextAlignmentCenter;label.text = @"Press Button";[self.view addSubview:label];[label release];//create toolbar using newtoolbar = [UIToolbar new];toolbar.barStyle = UIBarStyleDefault;[toolbar sizeToFit];toolbar.frame = CGRectMake(0, 410, 320, 50);//Add buttonsUIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd                                                                             target:self                                                                             action:@selector(pressButton1:)];UIBarButtonItem *systemItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction                                                                             target:self                                                                             action:@selector(pressButton2:)];UIBarButtonItem *systemItem3 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCameratarget:self action:@selector(pressButton3:)];//Use this to put space in between your toolbox buttonsUIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:nilaction:nil];//Add buttons to the arrayNSArray *items = [NSArray arrayWithObjects: systemItem1, flexItem, systemItem2, flexItem, systemItem3, nil];//release buttons[systemItem1 release];[systemItem2 release];[systemItem3 release];[flexItem release];//add array of buttons to toolbar[toolbar setItems:items animated:NO];[self.view addSubview:toolbar];}//Action methods for toolbar buttons:- (void) pressButton1:(id)sender{label.text = @"Add";}- (void) pressButton2:(id)sender{label.text = @"Take Action";}- (void) pressButton3:(id)sender{label.text = @"Camera";}- (void)dealloc {[toolbar release];[label release];    [super dealloc];}@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.