图片toolbar iphone

  

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 Toolbar
	UILabel *label;
	UIToolbar *toolbar;

	- (void)viewDidLoad {
	    [super viewDidLoad];

		//Create label
		label = [[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 new
		toolbar = [UIToolbar new];
		toolbar.barStyle = UIBarStyleDefault;
		[toolbar sizeToFit];
		toolbar.frame = CGRectMake(0, 410, 320, 50);

		//Add buttons
		UIBarButtonItem *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:UIBarButtonSystemItemCamera
		target:self action:@selector(pressButton3:)];

		//Use this to put space in between your toolbox buttons
		UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
		target:nil
		action:nil];

		//Add buttons to the array
		NSArray *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

 


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值