iOS 15-適配要點(diǎn)

  1. 增加UISheetPresentationController蜕该,通過它可以控制 Modal 出來的 UIViewController 的顯示大小俩莽,且可以通過拖拽手勢(shì)在不同大小之間進(jìn)行切換。只需要在跳轉(zhuǎn)的目標(biāo) UIViewController 做如下處理:
if let presentationController = presentationController as? UISheetPresentationController {
       // 顯示時(shí)支持的尺寸
       presentationController.detents = [.medium(), .large()]
       // 顯示一個(gè)指示器表示可以拖拽調(diào)整大小
       presentationController.prefersGrabberVisible = true
}
  1. UIButton支持更多配置疯兼。UIButton.Configuration是一個(gè)新的結(jié)構(gòu)體然遏,它指定按鈕及其內(nèi)容的外觀和行為。它有許多與按鈕外觀和內(nèi)容相關(guān)的屬性吧彪,如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) 
四種配置.png

間距.png
  1. 推出CLLocationButton用于一次性定位授權(quán),該內(nèi)容內(nèi)置于CoreLocationUI模塊勋又,但如果需要獲取定位的詳細(xì)信息仍然需要借助于CoreLocation苦掘。
let locationButton = CLLocationButton()
// 文字
locationButton.label = .currentLocation
locationButton.fontSize = 20
// 圖標(biāo)
locationButton.icon = .arrowFilled
// 圓角
locationButton.cornerRadius = 10
// tint
locationButton.tintColor = UIColor.systemPink
// 背景色
locationButton.backgroundColor = UIColor.systemGreen
// 點(diǎn)擊事件,應(yīng)該在在其中發(fā)起定位請(qǐng)求
locationButton.addTarget(self, action: #selector(getCurrentLocation), for: .touchUpInside)
  1. URLSession 推出支持 async/await 的 API楔壤,包括獲取數(shù)據(jù)鹤啡、上傳與下載。
let session = URLSession.shared
// 加載數(shù)據(jù)
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)
  1. 系統(tǒng)圖片支持多個(gè)層蹲嚣,支持多種渲染模式递瑰。
// hierarchicalColor:多層渲染,透明度不同
let config = UIImage.SymbolConfiguration(hierarchicalColor: .systemRed)
let image = UIImage(systemName: "square.stack.3d.down.right.fill", withConfiguration: config)
// paletteColors:多層渲染隙畜,設(shè)置不同風(fēng)格
let config2 = UIImage.SymbolConfiguration(paletteColors: [.systemRed, .systemGreen, .systemBlue])
let image2 = UIImage(systemName: "person.3.sequence.fill", withConfiguration: config2)
  1. UINavigationBar抖部、UIToolbar 和 UITabBar 設(shè)置顏色,需要使用 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
  1. UITableView 新增了屬性 sectionHeaderTopPadding慎颗,會(huì)給每一個(gè)section 的 header 增加一個(gè)默認(rèn)高度。
tableView.sectionHeaderTopPadding = 0
  1. UIImage 新增了幾個(gè)調(diào)整尺寸的方法言询。
 // preparingThumbnail
 UIImage(named: "sv.png")?.preparingThumbnail(of: CGSize(width: 200, height: 100))
 // prepareThumbnail俯萎,閉包中直接獲取調(diào)整后的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))
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請(qǐng)通過簡(jiǎn)信或評(píng)論聯(lián)系作者运杭。
  • 序言:七十年代末夫啊,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子县习,更是在濱河造成了極大的恐慌涮母,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,542評(píng)論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件躁愿,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡沪蓬,警方通過查閱死者的電腦和手機(jī)彤钟,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,822評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來跷叉,“玉大人逸雹,你說我怎么就攤上這事营搅。” “怎么了梆砸?”我有些...
    開封第一講書人閱讀 163,912評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵转质,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我帖世,道長(zhǎng)休蟹,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,449評(píng)論 1 293
  • 正文 為了忘掉前任日矫,我火速辦了婚禮赂弓,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘哪轿。我一直安慰自己盈魁,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,500評(píng)論 6 392
  • 文/花漫 我一把揭開白布窃诉。 她就那樣靜靜地躺著杨耙,像睡著了一般。 火紅的嫁衣襯著肌膚如雪飘痛。 梳的紋絲不亂的頭發(fā)上按脚,一...
    開封第一講書人閱讀 51,370評(píng)論 1 302
  • 那天,我揣著相機(jī)與錄音敦冬,去河邊找鬼辅搬。 笑死,一個(gè)胖子當(dāng)著我的面吹牛脖旱,可吹牛的內(nèi)容都是我干的堪遂。 我是一名探鬼主播,決...
    沈念sama閱讀 40,193評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼萌庆,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼溶褪!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起践险,我...
    開封第一講書人閱讀 39,074評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤猿妈,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后巍虫,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體彭则,經(jīng)...
    沈念sama閱讀 45,505評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,722評(píng)論 3 335
  • 正文 我和宋清朗相戀三年占遥,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了俯抖。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,841評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡瓦胎,死狀恐怖芬萍,靈堂內(nèi)的尸體忽然破棺而出尤揣,到底是詐尸還是另有隱情,我是刑警寧澤柬祠,帶...
    沈念sama閱讀 35,569評(píng)論 5 345
  • 正文 年R本政府宣布北戏,位于F島的核電站,受9級(jí)特大地震影響漫蛔,放射性物質(zhì)發(fā)生泄漏嗜愈。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,168評(píng)論 3 328
  • 文/蒙蒙 一惩猫、第九天 我趴在偏房一處隱蔽的房頂上張望芝硬。 院中可真熱鬧,春花似錦轧房、人聲如沸拌阴。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,783評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽迟赃。三九已至,卻和暖如春厂镇,著一層夾襖步出監(jiān)牢的瞬間纤壁,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,918評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工捺信, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留酌媒,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,962評(píng)論 2 370
  • 正文 我出身青樓迄靠,卻偏偏與公主長(zhǎng)得像秒咨,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子掌挚,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,781評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容