Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final class ViewController: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- let button = UIButton(type: .system)
- button.setTitle("Show Settings", for: .normal)
- button.addAction(UIAction() { _ in
- self.present(SettingsViewController(), animated: true)
- }, for: .touchUpInside)
- button.translatesAutoresizingMaskIntoConstraints = false
- view.addSubview(button)
- NSLayoutConstraint.activate([
- button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
- button.centerYAnchor.constraint(equalTo: view.centerYAnchor)
- ])
- }
- }
- private final class SettingsViewController: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- let host = UIHostingController(rootView: SettingsView().ignoresSafeArea(.all))
- addChild(host)
- host.view.translatesAutoresizingMaskIntoConstraints = false
- view.addSubview(host.view)
- NSLayoutConstraint.activate([
- host.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
- host.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
- host.view.topAnchor.constraint(equalTo: view.topAnchor),
- host.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)
- ])
- host.didMove(toParent: self)
- }
- }
- private struct SettingsView: View {
- var body: some View {
- NavigationStack {
- Form {
- ForEach(1..<25) { number in
- NavigationLink("Setting \(number)") {
- Text("Tap the back button and examine the scroll indicator.")
- .navigationTitle("Detail")
- }
- }
- }
- .scrollIndicatorsFlash(onAppear: true)
- .navigationTitle("Settings")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment