1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【SwiftUI】NavigationViewがiPhoneとiPadで見た目が変わる

Last updated at Posted at 2022-06-15

問題点

NavigationViewにスタイルを設定しないとiPhoneとiPadで見た目が変わってしまう。

iPad iPhone
simulator_screenshot_2BC0E84E-1339-48FC-AB61-B1A767296089.png simulator_screenshot_47A14FCB-0350-420A-8D03-610540F81D5C.png

コード

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                ForEach(0..<10) { _ in
                    Text("テキスト")
                }
            }
            .navigationTitle("タイトル")
        }
    }
}

解決策

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                ForEach(0..<10) { _ in
                    Text("テキスト")
                }
            }
            .navigationTitle("タイトル")
        }
        .navigationViewStyle(.stack)
    }
}

NavigationView.stackを指定すると同じ見た目で表示する事ができます。

.navigationViewStyle(.stack)
1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?