1、UINavigationBar
在iOS 15中,UINavigationBar默認(rèn)為透明。在滑動(dòng)時(shí)會(huì)有模糊效果。如果想要一直就是模糊效果,可以通過(guò)改變scrollEdgeAppearance屬性來(lái)實(shí)現(xiàn)。
解決辦法:
UINavigationBarAppearance*barApp=[[UINavigationBarAppearance alloc]init];
barApp.backgroundEffect=[UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
self.navigationBar.scrollEdgeAppearance=barApp;
UINavigationBar、UIToolbar 和 UITabBar 將在你的VC關(guān)聯(lián)滾動(dòng)視圖位于適當(dāng)?shù)倪吘墪r(shí)使用 scrollEdgeAppearance(或者如果您的視圖層級(jí)結(jié)構(gòu)中沒(méi)有 UIScrollView,更多內(nèi)容見(jiàn)下文)。
您必須使用 UIBarAppearance API 來(lái)自定義。UIToolbar 和 UITabBar 為此在 iOS 15 中添加了 scrollEdgeAppearance 屬性。
解決辦法:
object-c:
if(@available(iOS 15.0,*)){
UINavigationBarAppearance*barApp=[UINavigationBarAppearance new];
barApp.backgroundColor=[[UIColor blueColor]colorWithAlphaComponent:0.5];
//圖片
// navBarApperance.backgroundImage = [UIImage imageNamed:@"bgImage.png"];
// navBarApperance.backgroundImageContentMode = UIViewContentModeScaleToFill;
NSDictionary *dictM = @{ NSForegroundColorAttributeName:[UIColor blackColor]};
barApp.titleTextAttributes = dictM;
self.navigationController.navigationBar.scrollEdgeAppearance=barApp;
self.navigationController.navigationBar.standardAppearance=barApp;
}
swift:
if #available(iOS 15.0,*) {
let navBarAppecrace = UINavigationBarAppearance()
//顏色// navBarAppecrace.backgroundColor = UIColor.red
//圖片 navBarAppecrace.backgroundImage = UIImage.init(named: "bgImage.png")
navBarAppecrace.backgroundImageContentMode = .scaleToFill
navBarAppecrace.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
self.navigationController?.navigationBar.standardAppearance = navBarAppecrace
self.navigationController?.navigationBar.scrollEdgeAppearance = navBarAppecrace
} else {
self.navigationController?.navigationBar.barTintColor = UIColor.red
// self.navigationController?.navigationBar.setBackgroundImage(UIImage.init(named: "bgImage.png"), for: .any, barMetrics: .default)
}
1.1:TabBar
這里我看到好多文章說(shuō)和navigationbar是一個(gè)毛病,背景色和圖片設(shè)置在iOS 15上面都不會(huì)生效,但是我經(jīng)過(guò)測(cè)試,oc是沒(méi)有毛病的!swift語(yǔ)言確實(shí)會(huì)不生效。為了統(tǒng)一做了如下改動(dòng)
代碼和效果圖如下:
object-c:
if (@available(iOS 15.0, *)) {
UITabBarAppearance *tabBarAppearanc = [UITabBarAppearance new];
//顏色 tabBarAppearanc.backgroundColor = [UIColor greenColor];
// //圖片// tabBarAppearanc.backgroundImage = [UIImage imageNamed:@"bgImage.png"];
// tabBarAppearanc.backgroundImageContentMode = UIViewContentModeScaleToFill;
NSDictionary *dictM = @{ NSForegroundColorAttributeName:[UIColor redColor]};
tabBarAppearanc.stackedLayoutAppearance.selected.titleTextAttributes = dictM;
// tabBarAppearanc.stackedLayoutAppearance.normal.titleTextAttributes = .....
self.tabBar.scrollEdgeAppearance = tabBarAppearanc;
self.tabBar.standardAppearance = tabBarAppearanc;
} else {
// Fallback on earlier versions
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];
//顏色 [[UITabBar appearance] setBarTintColor:[UIColor greenColor]];
//圖片
// [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"bgImage.png"]];
}
swift:
if #available(iOS 15.0,*) {
let tabBarAppearanc = UITabBarAppearance.init()
//顏色
// tabBarAppearanc.backgroundColor = UIColor.green
//圖片 tabBarAppearanc.backgroundImage = UIImage.init(named: "bgImage.png")
tabBarAppearanc.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.red]
// tabBarAppearanc.stackedLayoutAppearance.normal.titleTextAttributes = .....
self.tabBar.standardAppearance = tabBarAppearanc
self.tabBar.scrollEdgeAppearance = tabBarAppearanc
}else{
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.black], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.red], for: .normal)
//顏色 UITabBar.appearance().barTintColor = UIColor.green
//圖片// UITabBar.appearance().backgroundImage = UIImage.init(named: "bgImage.png")
}
2、iOS 15 UITableView sectionHeader下移22像素
iOS 15中 UITableView 新增了一個(gè)屬性:sectionHeaderTopPadding。此屬性會(huì)給每一個(gè) section header 增加一個(gè)默認(rèn)高度,當(dāng)我們使用 UITableViewStylePlain 初始化UITableView 的時(shí)候,系統(tǒng)默認(rèn)給 section header 增高了22像素。
解決辦法:
object-c / swift:
if(@available(iOS 15.0,*)){tableView.sectionHeaderTopPadding=0;}???? //去掉headerpadding的高度
3、對(duì)狀態(tài)編程的支持:UICellConfigurationState;UICollectionViewCell、UITableViewCell都支持狀態(tài)變化時(shí)的block執(zhí)行了。
4、UICollectionViewLayout支持自動(dòng)高度;AutomaticDimension
5、json解析支持json5了
6、增加UISheetPresentationController,通過(guò)它可以控制 Modal 出來(lái)的 UIViewController 的顯示大小,且可以通過(guò)拖拽手勢(shì)在不同大小之間進(jìn)行切換。
7、UIButton支持更多配置。UIButton.Configuration是一個(gè)新的結(jié)構(gòu)體,它指定按鈕及其內(nèi)容的外觀和行為。它有許多與按鈕外觀和內(nèi)容相關(guān)的屬性,如cornerStyle、baseForegroundColor、baseBackgroundColor、buttonSize、title、image、subtitle、titlePadding、imagePadding、contentInsets、imagePlacement等。

之前我們可能要自定義一個(gè)類來(lái)實(shí)現(xiàn)這種按鈕,但是現(xiàn)在蘋果新增了特性
object-c:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor greenColor];
if (@available(iOS 15.0, *)) {
UIButtonConfiguration *conf = [UIButtonConfiguration tintedButtonConfiguration];
conf.cornerStyle = UIButtonConfigurationCornerStyleMedium;
[conf setImagePadding:5];
[conf setTitle:@"大標(biāo)題"];
[conf setSubtitle:@"副標(biāo)題"];
[conf setImage:[UIImage imageNamed:@"btnImage.png"]];
conf.imagePlacement = NSDirectionalRectEdgeLeading; button.configuration = conf;
} else {
// Fallback on earlier versions
}
swift:
let button:UIButton = UIButton.init(type: .custom)
button.backgroundColor = UIColor.green
if #available(iOS 15.0, *) {
var conf = UIButton.Configuration.tinted()
conf.cornerStyle = UIButton.Configuration.CornerStyle.medium
conf.imagePadding = 5
conf.title = "大標(biāo)題"
conf.subtitle = "副標(biāo)題"
conf.image = UIImage.init(named: "btnImage.png")
conf.imagePlacement = .leading
button.configuration = conf
}else{
// Fallback on earlier versions
}
8、推出CLLocationButton用于一次性定位授權(quán),該內(nèi)容內(nèi)置于CoreLocationUI模塊,但如果需要獲取定位的詳細(xì)信息仍然需要借助于CoreLocation。
9、URLSession 推出支持 async/await 的 API,包括獲取數(shù)據(jù)、上傳與下載
10、系統(tǒng)圖片支持多個(gè)層,支持多種渲染模式。
11、UIImage 新增了幾個(gè)調(diào)整尺寸的方法。
圖片的尺寸變換
object-c:
UIImage *modeImg = [UIImage imageNamed:@"bgImage.png"];
NSLog(@"圖片原尺寸%@",NSStringFromCGSize(modeImg.size));
if (@available(iOS 15.0, *)) {
modeImg = [modeImg imageByPreparingThumbnailOfSize:CGSizeMake(220, 100)];
NSLog(@"**111111**變換后圖片原尺寸%@",NSStringFromCGSize(modeImg.size));
[modeImg prepareThumbnailOfSize:CGSizeMake(220, 100) completionHandler:^(UIImage * _Nullable) {
NSLog(@"###222###變換后圖片原尺寸%@",NSStringFromCGSize(modeImg.size));
}];
} else {
// Fallback on earlier versions
};
//打印值
//2021-12-15 15:48:17.590981+0800 iOS15UI[71637:683127] 圖片原尺寸{674, 206}
//2021-12-15 15:48:17.598647+0800 iOS15UI[71637:683127] **111111**變換后圖片原尺寸{220, 100}
//2021-12-15 15:48:17.600537+0800 iOS15UI[71637:684293] ###222###變換后圖片原尺寸{220, 100}
swift:
var modImg = UIImage.init(named: "btnImage.png")
print("原圖片尺寸%@",modImg?.size as Any)
if #available(iOS 15.0, *) {
modImg = modImg?.preparingThumbnail(of: CGSize(width: 220, height: 100))
print("**111111**變換后圖片原尺寸%@",modImg?.size as Any)
modImg?.prepareThumbnail(of: CGSize(width: 220, height: 100)){
img in print("###222###變換后圖片原尺寸%@",modImg?.size as Any)
}
}
//打印值
//原圖片尺寸%@ Optional((124.0, 120.0))
//**111111**變換后圖片原尺寸%@ Optional((220.0, 100.0))
//###222###變換后圖片原尺寸%@ Optional((220.0, 100.0))