UISheetPresentationController
,經過它能夠控制 Modal 出來的 UIViewController 的顯示大小,且能夠經過拖拽手勢在不一樣大小之間進行切換。只須要在跳轉的目標 UIViewController 作以下處理:if let presentationController = presentationController as? UISheetPresentationController {
// 顯示時支持的尺寸
presentationController.detents = [.medium(), .large()]
// 顯示一個指示器表示能夠拖拽調整大小
presentationController.prefersGrabberVisible = true
}
複製代碼
UIButton
支持更多配置。UIButton.Configuration
是一個新的結構體,它指定按鈕及其內容的外觀和行爲。它有許多與按鈕外觀和內容相關的屬性,如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)
複製代碼
CLLocationButton
用於一次性定位受權,該內容內置於CoreLocationUI
模塊,但若是須要獲取定位的詳細信息仍然須要藉助於CoreLocation
。let locationButton = CLLocationButton()
// 文字
locationButton.label = .currentLocation
locationButton.fontSize = 20
// 圖標
locationButton.icon = .arrowFilled
// 圓角
locationButton.cornerRadius = 10
// tint
locationButton.tintColor = UIColor.systemPink
// 背景色
locationButton.backgroundColor = UIColor.systemGreen
// 點擊事件,應該在在其中發起定位請求
locationButton.addTarget(self, action: #selector(getCurrentLocation), for: .touchUpInside)
複製代碼
let session = URLSession.shared
// 加載數據
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)
複製代碼
// hierarchicalColor:多層渲染,透明度不一樣
let config = UIImage.SymbolConfiguration(hierarchicalColor: .systemRed)
let image = UIImage(systemName: "square.stack.3d.down.right.fill", withConfiguration: config)
// paletteColors:多層渲染,設置不一樣風格
let config2 = UIImage.SymbolConfiguration(paletteColors: [.systemRed, .systemGreen, .systemBlue])
let image2 = UIImage(systemName: "person.3.sequence.fill", withConfiguration: config2)
複製代碼
// 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
複製代碼
tableView.sectionHeaderTopPadding = 0
複製代碼
// preparingThumbnail
UIImage(named: "sv.png")?.preparingThumbnail(of: CGSize(width: 200, height: 100))
// prepareThumbnail,閉包中直接獲取調整後的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))
複製代碼
文中代碼已在 Xcode 13 Beta3 中測試經過, 案例源代碼下載地址。git