Buttons
比起之前,button加了2种样式Tinted、Filled:
button支持了更多的功能:
Button Configuration
直接设置configuratation属性,即可给button设置一种样式:
自定义button的configuration,并用它去创建button对象:
使用configurationUpdateHandler去自定义image在normal / highlighted状态下的显示情况,还有给button设置subtitle:
configurationUpdateHandler什么时候会被调用?当客户更改要购买的按钮数量时,应用程序会更新itemQuantityDescription,在didSet方法里,调用setNeedsUpdateConfiguration),这样就能让configurationUpdateHandler被调用了。
Activity indicator
设置button的属性showActivityIndicator = true,即可开启Activity indicator。
我们可以根据需求,用指示器替换image,只显示指示器。
Metrics adjustments
可以自定义contentInsets、titlePadding和imagePadding从而改变button内部布局情况:
Semantic styling
语义样式让创建按钮变得更加简单:
UIBackgroundConfiguration
使用UIBackgroundConfiguration给button设置默认的背景色,这样的话,结束indicator的时候,就会用上默认背景色:
Toggle buttons
什么是Toggle buttons?看看下面的图就明白:
| 未选中 | 选中 |
|---|---|
初始化一个Toggle button,只需要设置changesSelectionAsPrimaryAction = true即可,可以设置默认的选中状态:
Pop-up buttons
什么是Pop-up buttons?看看下面的图就明白:
①初始化一个Pop-up buttons,需要在changesSelectionAsPrimaryAction = true前提下,设置showMenuAsPrimaryAction = true。
②设置默认选中的项
③修改选中项
UIMenus
这是个给UIBarButtonItem加入UIMenus的例子,现在支持设置options: .singleSelection: