Sep 20, 2024

. This modifier allows developers to specify how the widget's images should be tinted, giving them control over the widget's appearance.widgetAccentedRenderingMode
widgetAccentedRenderingMode
modifier comes with four different modes, each offering a unique way to tint the widget's images:widgetAccentedRenderingMode
Jun 21, 2020
simply add this line to your viewControllernavigationController?.additionalSafeAreaInsets.top = 100// where 100 is the extra space
@IBAction func sliderSlided(_ sender: Any) {let top: CGFloat = (CGFloat(200 * ((sender as? UISlider)?.value ?? 1) - 0.5))navigationController?.additionalSafeAreaInsets.top = top}

@IBAction func slider2Slided(_ sender: Any) {let top: CGFloat = (CGFloat(100 * ((sender as? UISlider)?.value ?? 1)))additionalSafeAreaInsets.top = top}


Apr 12, 2020

@IBAction func push_nav(_ sender: Any) {let navVC = UINavigationController(rootViewController: ViewController())navigationController?.pushViewController(navVC, animated: true)}

class NavViewController: UINavigationController {override func viewDidLoad() {super.viewDidLoad()// we’ll work here in a bit}
import UIKit class NestedViewController: UIViewController {var rootVC: UIViewControllerweak var rootNavigation: UINavigationController?// 1init(rootNavigation: UINavigationController) {guard let vc = rootNavigation.viewControllers.first else {fatalError(“root has not been initialized”)}self.rootVC = vcself.rootNavigation = rootNavigationsuper.init(nibName: nil, bundle: nil)}required init?(coder: NSCoder) {fatalError(“init(coder:) has not been implemented”)}override func viewDidLoad() {super.viewDidLoad()// 2let childNavigation = rootNavigation ?? UINavigationController(rootViewController: rootVC)childNavigation.willMove(toParent: self)addChild(childNavigation)childNavigation.view.frame = view.frameview.addSubview(childNavigation.view)childNavigation.didMove(toParent: self)childNavigation.navigationBar.isTranslucent = false// 3 rootVC.navigationItem.leftBarButtonItem =UIBarButtonItem(barButtonSystemItem: .close, target: nil, action: #selector(back))}@IBAction func back() {navigationController?.popViewController(animated: true)}}
@IBAction func new_nav(_ sender: Any) {let cvc = UIStoryboard(name: “Main”, bundle: nil).instantiateViewController(identifier: “ViewController”)let nestedVC = NestedViewController(rootNavigation: UINavigationController(rootViewController: cvc))var nav = navigationControllerwhile ((nav?.navigationController) != nil) {nav = nav?.navigationController}DispatchQueue.main.async {nestedVC.rootVC.navigationController?.navigationBar.barTintColor = UIColor.random()}nav?.pushViewController(nestedVC, animated: true)}


final class AlwaysPoppableDelegate: NSObject, UIGestureRecognizerDelegate {weak var navigationController: UINavigationController?weak var originalDelegate: UIGestureRecognizerDelegate?override func responds(to aSelector: Selector!) -> Bool {if aSelector == #selector(gestureRecognizer(_:shouldReceive:)) {return true} else if let responds = originalDelegate?.responds(to: aSelector) {return responds} else {return false}}override func forwardingTarget(for aSelector: Selector!) -> Any? {return originalDelegate}func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {return true}}protocol Nested {var canNestedSwipeBack: Bool {get set}}
private let alwaysPoppableDelegate = AlwaysPoppableDelegate()
setNavigationBarHidden(true, animated: false)self.navigationBar.isOpaque = truealwaysPoppableDelegate.navigationController = selfinteractivePopGestureRecognizer?.delegate = alwaysPoppableDelegate
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {if let nav = navigationController, nav.isNavigationBarHidden, nav.viewControllers.count > 1 {// extra for nested nav viewcontrollersif let nested = (nav.viewControllers.last as? Nested) {return nested.canNestedSwipeBack} else if let nestedVC = (nav.viewControllers.last as? NestedViewController) {return (nestedVC.rootNavigation?.viewControllers.count ?? 0) <= 1} return true} else if let result = originalDelegate?.gestureRecognizer?(gestureRecognizer, shouldReceive: touch) {return result} else {return false}}
@IBAction func same_nav(_ sender: Any) {let cvc = UIStoryboard(name: “Main”, bundle: nil).instantiateViewController(identifier: “ViewController”)navigationController?.pushViewController(cvc, animated: true)}
Aug 8, 2019
Replicating Apple’s Dynamic Type just like in Apple stock apps.
Download Project
Apple enables user to change the font size of there app and Apple app set a good example in there app such as Music and Contact. You can play around with the setting by going in Setting > Accessibility > Larger Text then flip the switch and drag the bar to maximum. When you go back to Apple Music app, the layout will change.
before and after
We begin by creating a new project. In storyboard we put a nested stackView. Outside stackView contains imageView and a stackView with all the lables. Put constraints accordingly.
We also constraint imageView with aspect ratio and width.
Connect outside stackView to its viewController.
Then we add the following code//// ViewController.swift//import UIKitclass ViewController: UIViewController {@IBOutlet weak var stackView: UIStackView!override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view.}//1 override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {super.traitCollectionDidChange(previousTraitCollection) //2if previousTraitCollection?.preferredContentSizeCategory != traitCollection.preferredContentSizeCategory {let contentSize = traitCollection.preferredContentSizeCategoryif contentSize.isAccessibilityCategory {stackView.axis = .verticalstackView.alignment = .leadingstackView.spacing = 2} else {stackView.axis = .horizontalstackView.alignment = .centerstackView.spacing = 6}}}}
override func traitCollectionDidChange(_previousTraitCollection:UITraitCollection?)
This post is inspired by UseYourLoaf’s blogConfusians
© 2015 - 2025