Display Modes

Overview

Subjects

Disabling an Orientation Mode

Tags: #RoundedRectangle #CornerRadius #Toggle #OnTapGesture

Layout Toggle

struct UserView: View {
    var body: some View {
        Group {
            Text("Name: Paul")
            Text("Country: England")
            Text("Pets: Luna and Arya")
        }
        .font(.title)
    }
}

struct ContentView: View {
    @State private var layoutVertically = false

    var body: some View {
        Group {
            if layoutVertically {
                VStack {
                    UserView()
                }
            } else {
                HStack {
                    UserView()
                }
            }
        }
        .onTapGesture {
            layoutVertically.toggle()
        }
    }
}

Transition between Layout Modes Automatically (VStack / HStack)

Tags: #SizeClass #Layout #DisplayMode

This code looks at the space needed and then changes the layout. It also depends on the screen size you use.

struct UserView: View {
    var body: some View {
        Group {
            Text("Name: Paul")
            Text("Country: England")
            Text("Pets: Luna and Arya")
        }
        .font(.title)
    }
}

struct ContentView: View {
    @Environment(\.horizontalSizeClass) var sizeClass

    var body: some View {
        if sizeClass == .compact {
            VStack {
                UserView()
            }
        } else {
            HStack {
                UserView()
            }
        }
    }
}

or

struct UserView: View {
    var body: some View {
        Group {
            Text("Name: Paul")
            Text("Country: England")
            Text("Pets: Luna and Arya")
        }
        .font(.title)
    }
}

struct ContentView: View {
    @Environment(\.horizontalSizeClass) var sizeClass
    var body: some View {
        if sizeClass == .compact {
            VStack(content: UserView.init)
        } else {
            HStack(content: UserView.init)
        }
}

Making NavigationView work in Landscape (on iPhone)

Tags: ViewBuilder NavigationView #phoneOnlyNavigationView# #phoneOnlyStackNavigationView #navigationViewStyle #userInterfaceIdiom #devicetype

Size Classes

Tags: #sizeClass

Ne kadar yerinin olduğuna bakıyor. Yeteri kadar yerin var mı? Yoksa yok mu? Buna göre harekete geçebiliyorsun. Örneğin ekrandaki imgelerin ebatlarını değiştirebiliyorsun.

@Environment (.verticalsizeClass) var verticalsizeClass @Environment (.horizontalSizeClass) var horizontalSizeClass

Changing a view’s layout in response to size classes

Tags: #DynamicTypeSize

Sources

Videos

Articles / Documents

See also

Last updated