Xcode 13.0 編譯問題
一些老專案使用的編譯方式是 Legacy Build System (Deprecated),這個方式在 Xcode 13.0中會報編譯錯誤,
: The Legacy Build System will be removed in a future release. You can configure the selected build system and this deprecation message in File > Workspace Settings.

解決方案:
- 選單欄
File -> Workspace Settings -> BuildSystem - 上面選擇使用
New Build System (Default) - 下面選擇使用
Legacy Build System (Deprecated) - 勾選
Do not show a diagnostic issue about build system deprecation即可

UITabbar及UINavigationBar的背景顏色問題
從iOS 14升級到 iOS 15會出現 導航欄背景顏色失效
原因是設定顏色的方法在iOS 15中失效了
在iOS 13更新的API中分別新增了針對navigationBar、tabbar設定屬性,這些屬性包括滑動的時候產生的顏色、透明等等資訊,曾經的設定資訊在iOS 14以前的版本中還可以使用UINavigationBarAppearance 和 UITabBarAppearance進行設定,但是在iOS 15上被禁用,因此,你需要做如下修改
if (@available(iOS 15, *)) {
// 設定 TabBar
UITabBarAppearance *appearance = [[UITabBarAppearance alloc] init];
//tabBaritem title選中狀態顏色
appearance.stackedLayoutAppearance.selected.titleTextAttributes = @{
NSForegroundColorAttributeName: [UIColor blueColor]};
//tabBaritem title未選中狀態顏色
appearance.stackedLayoutAppearance.normal.titleTextAttributes = @{
NSForegroundColorAttributeName: [UIColor blueColor]};
//tabBar背景顏色
appearance.backgroundColor = [UIColor blackColor];
self.tabBarItem.scrollEdgeAppearance = appearance;
self.tabBarItem.standardAppearance = appearance;
// 設定 NavigationBar
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
appearance.backgroundColor = [UIColor blackColor];
self.navigationBar.standardAppearance = appearance;
self.navigationBar.scrollEdgeAppearance = appearance;
} else {
//設定navigationBar顏色
self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
// 設定tabBar背景色
self.tabBarController.tabBar.backgroundColor = [UIColor blueColor];
// 設定tabBarItem字體顏色
NSMutableDictionary<NSAttributedStringKey, id> *normalAttributes =[NSMutableDictionary dictionary];
[normalAttributes setValue:[UIColor blueColor] forKey:NSForegroundColorAttributeName];
[self.tabBarItem setTitleTextAttributes:normalAttributes.copy forState:UIControlStateNormal];
[self.tabBarItem setTitleTextAttributes:normalAttributes.copy forState:UIControlStateSelected];
}
其中 standardAppearance 和 scrollEdgeAppearance 的區別
- standardAppearance — 常規狀態
- scrollEdgeAppearance — 小螢屏手機橫屏時的狀態或滾動狀態
UITableView 新屬性
sectionHeaderTopPadding
官方檔案
/// Determines if the table view allows its cells to become focused.
/// When tableView:canFocusRowAtIndexPath: is implemented, its return value takes precedence over this method.
/// Defaults to a system derived value based on platform and other properties of the table view.
@property (nonatomic, getter=isPrefetchingEnabled) BOOL prefetchingEnabled
/// iOS 15中 tableView 會給每一個 section 的頂部(header以上)再加上一個 22像素 的高度,形成一個 section 和 section 之間的間距
使用
// 為了配合以前的開發習慣,我們只需要在創建實體的時候進行對間距的設定即可
if (@available(iOS 15.0, *)) {
tableView.sectionHeaderTopPadding = 0;
}
// 或者全域設定
if (@available(iOS 15.0, *)) {
[UITableView appearance].sectionHeaderTopPadding = 0;
}
增加 UISheetPresentationController
新增 UISheetPresentationController,通過它可以控制 Modal 出來的 UIViewController 的顯示大小,且可以通過拖拽手勢在不同大小之間進行切換,只需要在跳轉的目標 UIViewController 中做如下處理
if (@available(iOS 15.0, *)) {
if (self.sheetPresentationController) {
// 顯示支持的尺寸
self.sheetPresentationController.detents = @[UISheetPresentationControllerDetentIdentifierMedium, UISheetPresentationControllerDetentIdentifierLarge];
// 顯示一個指定器表示可以拖拽調整大小
self.sheetPresentationController.prefersGrabberVisible = true;
}
}
UIButton 支持更多配置
UIButton.Configuration 是一個新的屬性,它指定按鈕及其內容的外觀和行為,它有許多與按鈕外觀和內容相關的屬性,如 cornerStyle、buttonSize、macIdiomStyle、baseForegroundColor、image、imageColorTransformer、preferredSymbolConfigurationForImage等等
if (@available(iOS 15.0, *)) {
// Plain
UIButton *plain = [UIButton buttonWithConfiguration:[UIButtonConfiguration plainButtonConfiguration] primaryAction:nil];
plain setTitle:@"Plain" forState:UIControlStateNormal];
// Gray
UIButton *gray = [UIButton buttonWithConfiguration:[UIButtonConfiguration grayButtonConfiguration] primaryAction:nil];
[gray setTitle:@"Gray" forState:UIControlStateNormal];
// Tinted
UIButton *tinted = [UIButton buttonWithConfiguration:[UIButtonConfiguration tintedButtonConfiguration] primaryAction:nil];
[tinted setTitle:@"Tinted" forState:UIControlStateNormal];
// Filled
UIButton *filled = [UIButton buttonWithConfiguration:[UIButtonConfiguration tintedButtonConfiguration] primaryAction:nil];
[filled setTitle:@"Filled" forState:UIControlStateNormal];
}


CLLocationButton
推出CLLocationButton 用于一次性定位授權,該內容內置于 CoreLocationUI 模塊,但是如果需要獲取定位的詳細資訊,仍然需要借助于 CoreLocation,
#import <CoreLocationUI/CoreLocationUI.h>
CLLocationButton *locationButton = [[CLLocationButton alloc] init];
// 文字
locationButton.label = CLLocationButtonLabelCurrentLocation;
locationButton.fontSize = 20;
// 圖示
locationButton.icon = CLLocationButtonIconArrowFilled;
// 圓角
locationButton.cornerRadius = 10;
// tint
locationButton.tintColor = [UIColor systemPinkColor];
// 背景色
locationButton.backgroundColor = [UIColor systemGreenColor];
// 點擊事件,應該在其方法中發起定位請求
[locationButton addTarget:self action:@selector(getCurrentLocation) forControlEvents:UIControlEventTouchUpInside];
async/await Swift 專有
URLSession 推出支持 async/await 的 API,包括獲取資料、上傳與下載
// 加載資料
let (data, response) = try await URLSession.shared.data(from: url)
// 下載
let (localURL, _) = try await session.download(from: url)
// 上傳
let (_, response) = try await session.upload(for: request, from: data)
系統圖片支持多個層,支持多種渲染模式
// hierarchicalColor: 多層渲染,透明度不同
UIImageConfiguration *config = [UIImageSymbolConfiguration configurationWithHierarchicalColor:[UIColor systemRedColor]];
UIImage *image = [UIImage systemImageNamed:@"square.stack.3d.down.right.fill" withConfiguration:config];
// paletteColors: 多層渲染,設定不同風格
UIImageConfiguration *config2 = [UIImageSymbolConfiguration configurationWithPaletteColors:@[[UIColor systemRedColor], [UIColor systemGreenColor], [UIColor systemBlueColor]]];
UIImage *image2 = [UIImage systemImageNamed:@"person.3.sequence.fill" withConfiguration:config2];
// 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)
UIImage 新增調整尺寸的方法
// buPreparingThumbnail
[[UIImage imageNamed:@"sv.png"] imageByPreparingThumbnailOfSize:CGSizeMake(200, 100)];
// prepareThumbnail, block中直接獲取調整后的UIImage
[[UIImage imageNamed:@"sv.png"] prepareThumbnailOfSize:CGSizeMake(200, 100) completionHandler:^(UIImage * _Nullable image) {
// 需要回到主執行緒更新UI
}];
// 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))
-----未完待續-----
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/325624.html
標籤:其他
