widget 学习笔记
什么是wiget
iOS7引入了一个叫Today的东东,它和通知在一起出现在系统下拉菜单(通知栏)的两个tab中。每个APP可以建立一些扩展,其中在Today中展示的扩展就是wiget
A widget is an extension that displays a small amount of timely, useful information or app-specific functionality. For example, the News widget shows top headlines. Calendar provides two widgets, one that shows today’s events and one that shows what’s up next. Notes lets you preview recent notes and quickly create new notes, reminders, photos, and drawings. Widgets are highly customizable and can contain buttons, text, layout customizations, images, and more.
在today中的widget应性能时候优越,因为iOS对其限制很多。要考虑内存占用和用户及时响应,并且widget不能使用键盘。
如何创建一个wiget
在工程中新建一个target,选择Today Extension,就是通常意义上的窗口插件也就是widget。
这么模板会创建一个带有一个TodayViewController、一个info.plist和一个storyboard。如果不想使用storyboard需要修改info.plis的配置。
直接点击运行,在iOS10上的表现如下:
现在先来关心三个问题:
- TodayViewController的生命周期
- wi