iOS15适配

作者: TKYangx | 来源:发表于2021-10-24 15:25 被阅读0次

需要立即修改的


1. UINavigationBar、UIToolbar 和 UITabBar样式

UINavigationBar、UIToolbar 和 UITabBar 设置颜色,需要使用 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

2.UITableView-sectionHeaderTopPadding

UITableView 新增了属性 sectionHeaderTopPadding,会给每一个section 的 header 增加一个默认高度。

tableView.sectionHeaderTopPadding = 0

3. UIImageWriteToSavedPhotosAlbum

在iOS15中,UIImageWriteToSavedPhotosAlbum存储图片之后的回调不再返回图片了,会返回nil,如果在回调方法里面操作image有可能会直接Crash,目前的解决办法声明一个全局UIImage去记录,后面再去操作

其他新增

4.增加UISheetPresentationController

通过它可以控制 Modal 出来的 UIViewController 的显示大小,且可以通过拖拽手势在不同大小之间进行切换。只需要在跳转的目标 UIViewController 做如下处理:

if let presentationController = presentationController as? UISheetPresentationController {
   // 显示时支持的尺寸
   presentationController.detents = [.medium(), .large()]
   // 显示一个指示器表示可以拖拽调整大小
   presentationController.prefersGrabberVisible = true
}

5.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) 

6.推出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)

7.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)

8.系统图片支持多个层,支持多种渲染模式。

// 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)

9.UIImage 新增了几个调整尺寸的方法。

// 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
}
await UIImage(named: "sv.png")?.byPreparingThumbnail(ofSize: CGSize(width: 100, height: 100))

相关文章

  • html2canvas在ios15系统截图空白并刷新

    随着ios15系统的出现,项目适配ios15系统兼容性。 发现html2canvas在iOS15系统中截图空白并在...

  • iOS15 适配更新总结

    本文主要分享一下 iOS15 上适配方案,仅做开发记录使用,开发过程中通过使用陆续增加。 iOS15 的适配,很重...

  • iOS开发技巧之:iOS15 适配更新总结

    本文主要分享一下 iOS15 上适配方案,仅做开发记录使用,开发过程中通过使用陆续增加。 iOS15 的适配,很重...

  • iOS15适配

    iOS15适配主要是以下几点:UINavigationController、UITabBarController、...

  • iOS15适配

    对于iOS15适配汇总以及遇到的问题 注意:以下适配内容,必须适配的会以"必须"标出 UITableView Se...

  • iOS 15 适配笔记

    前言 环境 在 升级xcode 13.0 之后,正式开始支持 iOS15,就需要做适配 iOS15了,在 xcod...

  • 日期篇

    1. NSDateFormatter 1.1 系统适配 iOS15以下dateFormat = @"HH:mm" ...

  • iOS15适配

    以iOS15和xcode13为环境基础,iOS15适配的一些更改和调整。 UINavigationBar UITa...

  • iOS15适配

    以iOS15和xcode13为环境基础,iOS15适配的一些更改和调整。 UINavigationBar UITa...

  • IOS15审核最新详细版

    IOS15适配 导航栏UINavigationBar 从 iOS 15 开始,UINavigationBar、UI...

网友评论

    本文标题:iOS15适配

    本文链接:https://www.haomeiwen.com/subject/wwwraltx.html