Refresh UIPageViewController – reorder pages and add new pages

I found a workaround to force UIPageViewController to forget about cached view controllers of neighboring pages that are currently not displayed: pageViewController.dataSource = nil; pageViewController.dataSource = self; I do this everytime I change the set of pages. Of course this doesn’t affect the currently displayed page. With this workaround I avoid the caching bug and … Read more

How to set back button text in iOS navigation controller?

The back button belongs to the previous view controller, not the one currently presented on screen. To modify the back button you should update it before pushing, on the view controller that initiated the segue: override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let backItem = UIBarButtonItem() backItem.title = “Something Else” navigationItem.backBarButtonItem = backItem // This … Read more

How to detect Light\Dark mode change in iOS 13?

SwiftUI With a simple environment variable on the \.colorScheme key: struct ContentView: View { @Environment(\.colorScheme) var colorScheme var body: some View { Text(colorScheme == .dark ? “Its Dark” : “Its. not dark! (Light)”) } } UIKit As it described in WWDC 2019 – Session 214 around 23:30. As I expected, this function is getting called … Read more

How reliable is KVO with UIKit

UIKit is mostly NOT KVO compliant. This is mostly because UIView acts as high-level wrapper for CALayer, so when you eg. change the frame property of an UIView, it will change the layers frame but leave eg. the bounds property of the UIView untouched, so no observer will be triggered for the view.bounds path, because … Read more