UIButton: Insets

UIButton 支持设置 contentEdgeInsetstitleEdgeInsetsimageEdgeIntets, 其中 contentEdgeInsets 会影响 instrinsicConentSize,而 titleEdgeInsetsimageEdgeInsets 则不然。此外因为都是 UIEdgeInsets,不支持 NSDirectionalEdgeInsets,所以需要自己通过 userInterfaceLayoutDirection 获取阅读方向。

Package 本地化

首先在 package.swift 里增加对应的参数 defaultLocalizaiton,并为 targets 设置 resources

UIView 设置圆角

通过 UIViewlayer.cornerRadius 可以设置圆角;此外还可以通过 layer.maskedCorners 指定圆角生效的位置。

WWDC21:从照片中获取文本 Text from Camera

iOS15 带来了新的 API,类似 OCR,可以使用相机实时图片中的文本,并自动填充到文本控件中。可以通过设置 UITextContentTypeUIKeyboardType ,或使用新的 Action.captureTextFromCamera(responder:, identifier:) 实现,或自定义 Image View 实现 UIKeyInput 协议。

WWDC21: StoreKit 2 简介 Meet StoreKit 2

新的 StoreKit 2 包含 Products / Purchases / Transaction Info / Transaction history / Subscription status,基于 Swift async/await 设计,只需一行代码即可完成支付,还可以指定 appAccountToken 标识交易,打通自建账号系统;此外借由 automatic validation,可以方便的在 iOS 端完成支付验证,当然自定义验证依然支持;通过监听 transaction update,可以更好的处理一些需要额外验证操作的交易。