继承关系:UIToolBar -> UIView -> UIResponder -> NSObject。

  toolBar是一个工具栏,用于显示一个或多个按钮。其按钮叫做toolBar items,是UIBarButtonItem对象。

@property(nonatomic, copy) NSArray *items   //在toolBar上显示的items。其中的每个item都是UIBarButtonItem对象。按照其在数组中的位置依次显示。该属性的任何变化不会产生动画效果。默认为nil值。

@property(nonatomic) UIBarStyle barStyle   // 确定toolBar的外观。默认值为UIBarStyleDefault,其为白色的背景和黑色的内容。

@property(nonatomic, retain) UIColor *barTintColor   // 指定toolBar的背景颜色。

@property(nonatomic, retain) UIColor *tintColor   // 指定item的颜色。

@property(nonatomic, assign, getter=isTranslucent) BOOL translucent   // 指明toolBar是否是透明的,默认为YES。

@property(nonatomic, assign) id<UIToolbarDelegate> delegate   //委托对象应该遵守UIToolBarDelegate协议。


- (void)setBackgroundImage:(UIImage *)backgroundImage forToolbarPosition:(UIBarPosition)topOrBottom barMetrics:(UIBarMetrics)barMetrics

// 设置图片作为toolBar的背景。

- (void)setItems:(NSArray *)items animated:(BOOL)animated   // 如果animated为YES,则当toolBar的items改变时,附带一些动画效果。

- (void)setShadowImage:(UIImage *)shadowImage forToolbarPosition:(UIBarPosition)topOrBottom   //如果想要使用自定义的shadow image,必须用setBackgroundImage:forToolbarPosition:barMetrics:方法设置自定义的背景图片。如果使用了默认的背景图片,不管shadowImage为什么,都使用默认的值。

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
CGRect bound = [[UIScreen mainScreen] bounds];
self.window = [[UIWindow alloc] initWithFrame:bound];
self.window.rootViewController = [[UIViewController alloc] init]; CGRect toolBarRect = CGRectMake(, bound.size.height / , bound.size.width, );
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:toolBarRect]; UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"item1"
style:UIBarButtonItemStyleDone
target:self
action:nil];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"item2"
style:UIBarButtonItemStyleDone
target:self
action:nil];
// UIImage *image1 = [UIImage imageNamed:@"beauty0.jpg"];
// UIImage *image2 = [UIImage imageNamed:@"beauty3.jpg"];
// [toolBar setBackgroundImage:image1 forToolbarPosition:UIBarPositionBottom barMetrics:UIBarMetricsDefault];
// [toolBar setShadowImage:image2 forToolbarPosition:UIBarPositionBottom]; // toolBar.items = @[item1, item2];
[toolBar setItems:@[item1, item2] animated:YES];
toolBar.barTintColor = [UIColor redColor];
toolBar.tintColor = [UIColor whiteColor]; [self.window addSubview:toolBar];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

运行结果为:

UIToolBar - 官方文档的更多相关文章

  1. 【AutoMapper官方文档】DTO与Domin Model相互转换(上)

    写在前面 AutoMapper目录: [AutoMapper官方文档]DTO与Domin Model相互转换(上) [AutoMapper官方文档]DTO与Domin Model相互转换(中) [Au ...

  2. 2DToolkit官方文档中文版打地鼠教程(三):Sprite Collections 精灵集合

    这是2DToolkit官方文档中 Whack a Mole 打地鼠教程的译文,为了减少文中过多重复操作的翻译,以及一些无必要的句子,这里我假设你有Unity的基础知识(例如了解如何新建Sprite等) ...

  3. 2DToolkit官方文档中文版打地鼠教程(二):设置摄像机

    这是2DToolkit官方文档中 Whack a Mole 打地鼠教程的译文,为了减少文中过多重复操作的翻译,以及一些无必要的句子,这里我假设你有Unity的基础知识(例如了解如何新建Sprite等) ...

  4. 2DToolkit官方文档中文版打地鼠教程(一):初始设置

    这是2DToolkit官方文档中 Whack a Mole 打地鼠教程的译文,为了减少文中过多重复操作的翻译,以及一些无必要的句子,这里我假设你有Unity的基础知识(例如了解如何新建Sprite等) ...

  5. 【AutoMapper官方文档】DTO与Domin Model相互转换(中)

    写在前面 AutoMapper目录: [AutoMapper官方文档]DTO与Domin Model相互转换(上) [AutoMapper官方文档]DTO与Domin Model相互转换(中) [Au ...

  6. 【AutoMapper官方文档】DTO与Domin Model相互转换(下)

    写在前面 AutoMapper目录: [AutoMapper官方文档]DTO与Domin Model相互转换(上) [AutoMapper官方文档]DTO与Domin Model相互转换(中) [Au ...

  7. Ionic2系列——Ionic 2 Guide 官方文档中文版

    最近一直没更新博客,业余时间都在翻译Ionic2的文档.之前本来是想写一个入门,后来觉得干脆把官方文档翻译一下算了,因为官方文档就是最好的入门教程.后来越翻译越觉得这个事情确实比较费精力,不知道什么时 ...

  8. Kotlin开发语言文档(官方文档)-- 目录

    开始阅读Kotlin官方文档.先上文档目录.有些内容还未阅读,有些目录标目翻译还需琢磨琢磨.后续再将具体内容的链接逐步加上. 文档链接:https://kotlinlang.org/docs/kotl ...

  9. 一起学微软Power BI系列-官方文档-入门指南(1)Power BI初步介绍

    我们在前一篇文章微软新神器-Power BI,一个简单易用,还用得起的BI产品中,我们初步介绍了Power BI的基本知识.由于Power BI是去年开始微软新发布的一个产品,虽然已经可以企业级应用, ...

随机推荐

  1. html之head标签

    本文内容: head标签 介绍 常用子标签 meta title link style script 首发时间:2018-02-12 修改: 2018-04-24:修改了标题名称,重新排版了内容,使得 ...

  2. Javascript数组系列一之栈与队列

    所谓数组(英语:Array),是有序的元素序列. 若将有限个类型相同的变量的集合命名,那么这个名称为数组名. 组成数组的各个变量称为数组的分量,也称为数组的元素,有时也称为下标变量. ---百度百科 ...

  3. linux下ssh通过公钥登录服务器

    经常会通过ssh登录远程服务器,一种是通过密码方式登录,一种是通过公钥登录. 如何设置通过公钥登录服务器 1. 首先生成自己的公钥和私钥 ssh-keygen 命令用来生成公钥和私钥 -t 用来指定密 ...

  4. 一张图教你读懂AI简史

  5. MS SQL作业Schedule的限制注意事项

      最近遇到了一个关于MS SQL作业Schedule下有限制的特殊案例,有一个作业,用户要求执行的时间为:9:30,14:30,16:30, 19:00,于是我设置了两个Schedule,其中一个每 ...

  6. 自动化测试基础篇--Selenium select下拉框

    摘自https://www.cnblogs.com/sanzangTst/p/7681523.html 一.什么是下拉框 下拉框是多项选择项,选择其中一种,类似下面(以百度搜索设置为例) 源代码如下所 ...

  7. 测试TCP 和 UDP 端口的方法

    测试 TCP 端口: telnel IP PORT nc -vz IP PORT 测试 UDP 端口: nc -vuz IP PORT 其中 -u 表示使用 udp 协议来进行测试. -u, --ud ...

  8. Linux安装Python3后,如何使用pip命令

    系统环境:CentOS7.4 已安装好Python3.6.5 Python3.6.5自带pip 使用pip安装第三方库,可运行指令,例如安装paramiko库: python -m pip insta ...

  9. LeetCode算法题-Contains Duplicate(Java实现)

    这是悦乐书的第192次更新,第196篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第52题(顺位题号是217).给定一个整数数组,查找数组是否包含任何重复项.如果数组中至 ...

  10. [福大软工] Z班 团队Beta阶段成绩汇总

    Beta敏捷冲刺得分 队伍名 1 2 3 4 5 总分 Dipper 10 10 10 10 10 50 SWSD 9 9 9 9 7 43 五成胜算 10 10 10 10 10 50 人月神教 0 ...