如何以编程方式将UIToolbar添加到iOS应用? [英] How to add a UIToolbar programmatically to an iOS app?

查看:82
本文介绍了如何以编程方式将UIToolbar添加到iOS应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎找不到像问题标题所描述的那样的教程.我想了解仅需在​​何处声明UIToolbar,以及如何将其放入我的视图层.

Can't seem to find a tutorial which does as the question title describes. I'd like to understand just where the UIToolbar needs to be declared and how to get it onto my view layer.

推荐答案

UIToolbarUIView的子类,因此对该问题的简短回答是:就像其他任何视图一样.

UIToolbar is a subclass of UIView, so the short answer to your question is: just like any other view.

具体地说,这是一个如何以编程方式创建工具栏的示例.此代码段中的上下文是视图控制器的viewDidLoad.

Specifically, this is an example of how to programmatically create a toolbar. The context in this snippet is viewDidLoad of a view controller.

UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
NSMutableArray *items = [[NSMutableArray alloc] init];
[items addObject:[[[UIBarButtonItem alloc] initWith....] autorelease]];
[toolbar setItems:items animated:NO];
[items release];
[self.view addSubview:toolbar];
[toolbar release];

请参见 UIToolbar 有关详细信息,请参见UIBarButtonItem 文档.

这篇关于如何以编程方式将UIToolbar添加到iOS应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆