- 增加
UISheetPresentationController
蜕该,通過它可以控制 Modal 出來的 UIViewController 的顯示大小俩莽,且可以通過拖拽手勢(shì)在不同大小之間進(jìn)行切換。只需要在跳轉(zhuǎn)的目標(biāo) UIViewController 做如下處理:
if let presentationController = presentationController as? UISheetPresentationController {
// 顯示時(shí)支持的尺寸
presentationController.detents = [.medium(), .large()]
// 顯示一個(gè)指示器表示可以拖拽調(diào)整大小
presentationController.prefersGrabberVisible = true
}
-
UIButton
支持更多配置疯兼。UIButton.Configuration
是一個(gè)新的結(jié)構(gòu)體然遏,它指定按鈕及其內(nèi)容的外觀和行為。它有許多與按鈕外觀和內(nèi)容相關(guān)的屬性吧彪,如cornerStyle待侵、baseForegroundColor、baseBackgroundColor姨裸、buttonSize秧倾、title香拉、image、subtitle中狂、titlePadding凫碌、imagePadding、contentInsets胃榕、imagePlacement
等盛险。
// Plain
let plain = UIButton(configuration: .plain(), primaryAction: nil)
plain.setTitle("Plain", for: .normal)
// Gray
let gray = UIButton(configuration: .gray(), primaryAction: nil)
gray.setTitle("Gray", for: .normal)
// Tinted
let tinted = UIButton(configuration: .tinted(), primaryAction: nil)
tinted.setTitle("Tinted", for: .normal)
// Filled
let filled = UIButton(configuration: .filled(), primaryAction: nil)
filled.setTitle("Filled", for: .normal)
四種配置.png
間距.png
- 推出
CLLocationButton
用于一次性定位授權(quán),該內(nèi)容內(nèi)置于CoreLocationUI
模塊勋又,但如果需要獲取定位的詳細(xì)信息仍然需要借助于CoreLocation
苦掘。
let locationButton = CLLocationButton()
// 文字
locationButton.label = .currentLocation
locationButton.fontSize = 20
// 圖標(biāo)
locationButton.icon = .arrowFilled
// 圓角
locationButton.cornerRadius = 10
// tint
locationButton.tintColor = UIColor.systemPink
// 背景色
locationButton.backgroundColor = UIColor.systemGreen
// 點(diǎn)擊事件,應(yīng)該在在其中發(fā)起定位請(qǐng)求
locationButton.addTarget(self, action: #selector(getCurrentLocation), for: .touchUpInside)
- URLSession 推出支持 async/await 的 API楔壤,包括獲取數(shù)據(jù)鹤啡、上傳與下載。
let session = URLSession.shared
// 加載數(shù)據(jù)
let (data, response) = try await session.data(from: url)
// 下載
let (localURL, _) = try await session.download(from: url)
// 上傳
let (_, response) = try await session.upload(for: request, from: data)
- 系統(tǒng)圖片支持多個(gè)層蹲嚣,支持多種渲染模式递瑰。
// hierarchicalColor:多層渲染,透明度不同
let config = UIImage.SymbolConfiguration(hierarchicalColor: .systemRed)
let image = UIImage(systemName: "square.stack.3d.down.right.fill", withConfiguration: config)
// paletteColors:多層渲染隙畜,設(shè)置不同風(fēng)格
let config2 = UIImage.SymbolConfiguration(paletteColors: [.systemRed, .systemGreen, .systemBlue])
let image2 = UIImage(systemName: "person.3.sequence.fill", withConfiguration: config2)
- UINavigationBar抖部、UIToolbar 和 UITabBar 設(shè)置顏色,需要使用 UIBarAppearance APIs议惰。
// UINavigationBar
let navigationBarAppearance = UINavigationBarAppearance()
navigationBarAppearance.backgroundColor = .red
navigationController?.navigationBar.scrollEdgeAppearance = navigationBarAppearance
navigationController?.navigationBar.standardAppearance = navigationBarAppearance
// UIToolbar
let toolBarAppearance = UIToolbarAppearance()
toolBarAppearance.backgroundColor = .blue
navigationController?.toolbar.scrollEdgeAppearance = toolBarAppearance
navigationController?.toolbar.standardAppearance = toolBarAppearance
// UITabBar
let tabBarAppearance = UITabBarAppearance()
toolBarAppearance.backgroundColor = .purple
tabBarController?.tabBar.scrollEdgeAppearance = tabBarAppearance
tabBarController?.tabBar.standardAppearance = tabBarAppearance
- UITableView 新增了屬性 sectionHeaderTopPadding慎颗,會(huì)給每一個(gè)section 的 header 增加一個(gè)默認(rèn)高度。
tableView.sectionHeaderTopPadding = 0
- UIImage 新增了幾個(gè)調(diào)整尺寸的方法言询。
// preparingThumbnail
UIImage(named: "sv.png")?.preparingThumbnail(of: CGSize(width: 200, height: 100))
// prepareThumbnail俯萎,閉包中直接獲取調(diào)整后的UIImage
UIImage(named: "sv.png")?.prepareThumbnail(of: CGSize(width: 200, height: 100)) { image in
// 需要回到主線程更新UI
}
// byPreparingThumbnail
await UIImage(named: "sv.png")?.byPreparingThumbnail(ofSize: CGSize(width: 100, height: 100))