Ios15 adaptation

Time:2022-5-9

Need immediate modification


1. Uinavigationbar, uitoolbar and uitabbar styles

Uinavigationbar, uitoolbar and uitabbar need to use uibarappearance APIs to set colors.

// 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 adds the attribute sectionheadertoppadding, which will add a default height to the header of each section.

tableView.sectionHeaderTopPadding = 0

3. UIImageWriteToSavedPhotosAlbum

In ios15, the callback after uiimagewritetosavedphotosalbum stores the picture will no longer return the picture, but will return nil. If the image is operated in the callback method, it may directly crash. The current solution is to declare a global uiimage to record, and then operate later

Other additions

4. Add uisheetpresentationcontroller

It can control the display size of uiviewcontroller from modal, and can switch between different sizes by dragging gesture. You only need to do the following in the target uiviewcontroller of the jump:

if let presentationController = presentationController as? UISheetPresentationController {
   //Supported dimensions when displayed
   presentationController.detents = [.medium(), .large()]
   //Displays an indicator indicating that you can drag and drop to resize
   presentationController.prefersGrabberVisible = true
}

5. Uibutton supports more configurations.

UIButton. Configuration is a new structure that specifies the appearance and behavior of buttons and their contents. It has many attributes related to the appearance and content of buttons, such as cornerstyle, baseforegroundcolor, basebackgroundcolor, buttonsize, title, image, subtitle, titlepadding, imagepadding, contentinserts, imageplacement, etc.

// 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. Launch cllocationbutton for one-time location authorization

This content is built into the corelocation UI module, but if you need to obtain the location details, you still need to use corelocation.

let locationButton = CLLocationButton()
//Writing
locationButton.label = .currentLocation
locationButton.fontSize = 20
//Icon
locationButton.icon = .arrowFilled
//Fillet
locationButton.cornerRadius = 10
// tint
locationButton.tintColor = UIColor.systemPink
//Background color
locationButton.backgroundColor = UIColor.systemGreen
//Click the event in which the location request should be initiated
locationButton.addTarget(self, action: #selector(getCurrentLocation), for: .touchUpInside)

7. Urlsession launched an API that supports async / await, including data acquisition, upload and download.

//Load data
let (data, response) = try await URLSession.shared.data(from: url)
//Download
let (localURL, _) = try await session.download(from: url)
//Upload
let (_, response) = try await session.upload(for: request, from: data)

8. Support multiple picture rendering modes.

//Hierarchical color: multi layered rendering with different transparency
let config = UIImage.SymbolConfiguration(hierarchicalColor: .systemRed)
let image = UIImage(systemName: "square.stack.3d.down.right.fill", withConfiguration: config)
//Palettecolors: multi layer rendering with different styles
let config2 = UIImage.SymbolConfiguration(paletteColors: [.systemRed, .systemGreen, .systemBlue])
let image2 = UIImage(systemName: "person.3.sequence.fill", withConfiguration: config2)

9. Uiimage adds several sizing methods.

// preparingThumbnail
UIImage(named: "sv.png")?.preparingThumbnail(of: CGSize(width: 200, height: 100))
//Preparethumbnail: directly obtain the adjusted uiimage in the closure
UIImage(named: "sv.png")?.prepareThumbnail(of: CGSize(width: 200, height: 100)) { image in
    //You need to go back to the main thread to update the UI
}
await UIImage(named: "sv.png")?.byPreparingThumbnail(ofSize: CGSize(width: 100, height: 100))

Recommended Today

How to quickly build a front-end monitoring system

1、 Why should the front end be a monitoring system The development environment of the front-end is relatively complex. The pages may be displayed differently in different browsers, wechat and other apps. The user’s network speed and mobile phone performance will also affect the page access speed. It may be more obvious on the mobile […]