WWDC 2021 – Meet the UIKit button system

Buttons

比起之前,button加了2种样式TintedFilled

image.png

button支持了更多的功能:

image.png

Button Configuration

直接设置configuratation属性,即可给button设置一种样式:

Xnip2021-08-05_11-31-40.jpg

自定义button的configuration,并用它去创建button对象:

image.png

使用configurationUpdateHandler去自定义image在normal / highlighted状态下的显示情况,还有给button设置subtitle:

image.png

configurationUpdateHandler什么时候会被调用?当客户更改要购买的按钮数量时,应用程序会更新itemQuantityDescription,在didSet方法里,调用setNeedsUpdateConfiguration),这样就能让configurationUpdateHandler被调用了。

image.png

Activity indicator

设置button的属性showActivityIndicator = true,即可开启Activity indicator。

我们可以根据需求,用指示器替换image,只显示指示器。

Xnip2021-08-05_10-50-17.jpg

Metrics adjustments

可以自定义contentInsetstitlePaddingimagePadding从而改变button内部布局情况:

Xnip2021-08-05_10-56-46.jpg

Semantic styling

语义样式让创建按钮变得更加简单:

image.png

UIBackgroundConfiguration

使用UIBackgroundConfiguration给button设置默认的背景色,这样的话,结束indicator的时候,就会用上默认背景色:

image.png

Toggle buttons

什么是Toggle buttons?看看下面的图就明白:

未选中 选中
Xnip2021-08-05_13-04-01.jpg Xnip2021-08-05_13-03-43.jpg

初始化一个Toggle button,只需要设置changesSelectionAsPrimaryAction = true即可,可以设置默认的选中状态:

image.png

Pop-up buttons

什么是Pop-up buttons?看看下面的图就明白:

image.png

①初始化一个Pop-up buttons,需要在changesSelectionAsPrimaryAction = true前提下,设置showMenuAsPrimaryAction = true

②设置默认选中的项

③修改选中项

image.png

UIMenus

这是个给UIBarButtonItem加入UIMenus的例子,现在支持设置options: .singleSelection

Xnip2021-08-05_14-59-24.jpg

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享