Guest User

Untitled

a guest
Nov 5th, 2026
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.92 KB | Source Code | 0 0
  1. final class ViewController: UIViewController {
  2.     override func viewDidLoad() {
  3.         super.viewDidLoad()
  4.        
  5.         let button = UIButton(type: .system)
  6.         button.setTitle("Show Settings", for: .normal)
  7.         button.addAction(UIAction() { _ in
  8.             self.present(SettingsViewController(), animated: true)
  9.         }, for: .touchUpInside)
  10.         button.translatesAutoresizingMaskIntoConstraints = false
  11.         view.addSubview(button)
  12.         NSLayoutConstraint.activate([
  13.             button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
  14.             button.centerYAnchor.constraint(equalTo: view.centerYAnchor)
  15.         ])
  16.     }
  17. }
  18.  
  19. private final class SettingsViewController: UIViewController {
  20.     override func viewDidLoad() {
  21.         super.viewDidLoad()
  22.        
  23.         let host = UIHostingController(rootView: SettingsView().ignoresSafeArea(.all))
  24.         addChild(host)
  25.         host.view.translatesAutoresizingMaskIntoConstraints = false
  26.         view.addSubview(host.view)
  27.         NSLayoutConstraint.activate([
  28.             host.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
  29.             host.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
  30.             host.view.topAnchor.constraint(equalTo: view.topAnchor),
  31.             host.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)
  32.         ])
  33.         host.didMove(toParent: self)
  34.     }
  35. }
  36.  
  37. private struct SettingsView: View {
  38.     var body: some View {
  39.         NavigationStack {
  40.             Form {
  41.                 ForEach(1..<25) { number in
  42.                     NavigationLink("Setting \(number)") {
  43.                         Text("Tap the back button and examine the scroll indicator.")
  44.                             .navigationTitle("Detail")
  45.                     }
  46.                 }
  47.             }
  48.             .scrollIndicatorsFlash(onAppear: true)
  49.             .navigationTitle("Settings")
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment