1甜刻、UINavigationBar
在iOS 15中绍撞,UINavigationBar默認為透明。在滑動時會有模糊效果罢吃。如果想要一直就是模糊效果楚午,可以通過改變scrollEdgeAppearance屬性來實現(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)?shù)倪吘墪r使用 scrollEdgeAppearance(或者如果您的視圖層級結(jié)構(gòu)中沒有 UIScrollView,更多內(nèi)容見下文)阱驾。
您必須使用 UIBarAppearance API 來自定義就谜。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
這里我看到好多文章說和navigationbar是一個毛病里覆,背景色和圖片設(shè)置在iOS 15上面都不會生效丧荐,但是我經(jīng)過測試,oc是沒有毛病的喧枷!swift語言確實會不生效虹统。為了統(tǒ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 新增了一個屬性:sectionHeaderTopPadding隧甚。此屬性會給每一個 section header 增加一個默認高度车荔,當(dāng)我們使用 UITableViewStylePlain 初始化UITableView 的時候,系統(tǒng)默認給 section header 增高了22像素戚扳。
解決辦法:
object-c / swift:
if(@available(iOS 15.0,*)){tableView.sectionHeaderTopPadding=0;}???? //去掉headerpadding的高度
3忧便、對狀態(tài)編程的支持:UICellConfigurationState;UICollectionViewCell帽借、UITableViewCell都支持狀態(tài)變化時的block執(zhí)行了珠增。
4、UICollectionViewLayout支持自動高度砍艾;AutomaticDimension
5蒂教、json解析支持json5了
6、增加UISheetPresentationController脆荷,通過它可以控制 Modal 出來的 UIViewController 的顯示大小凝垛,且可以通過拖拽手勢在不同大小之間進行切換。
7、UIButton支持更多配置苔严。UIButton.Configuration是一個新的結(jié)構(gòu)體定枷,它指定按鈕及其內(nèi)容的外觀和行為。它有許多與按鈕外觀和內(nèi)容相關(guān)的屬性届氢,如cornerStyle欠窒、baseForegroundColor、baseBackgroundColor退子、buttonSize岖妄、title、image寂祥、subtitle荐虐、titlePadding、imagePadding丸凭、contentInsets福扬、imagePlacement等。
之前我們可能要自定義一個類來實現(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模塊虽界,但如果需要獲取定位的詳細信息仍然需要借助于CoreLocation汽烦。
9、URLSession 推出支持 async/await 的 API莉御,包括獲取數(shù)據(jù)撇吞、上傳與下載
10、系統(tǒng)圖片支持多個層礁叔,支持多種渲染模式牍颈。
11、UIImage 新增了幾個調(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))