Post

Replies

Boosts

Views

Activity

Reply to SwiftUI tabItem Label Text Cut Off on iPad
You can simply use HStack to separate the name text and its corresponding image. import SwiftUI struct ContentView: View { var body: some View { TabView{ FirstView() .tabItem { HStack { Text("Save") .fixedSize() Image(systemName: "lock.fill") } } SecondView() .tabItem { HStack { Text("Things") .fixedSize() Image(systemName: "message.fill") } } } } } struct FirstView: View { var body: some View { Text("First") } } struct SecondView: View { var body: some View { Text("Second") } }
Sep ’23
Reply to Use context menu to navigate to another view
I am able to use the contextMenu guy to navigate to another View. Do I miss something? import SwiftUI struct ContentView: View { var body: some View { NavigationStack { FirstView() } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } struct FirstView: View { @State var goToSecond = false var body: some View { VStack { Text("FirstView") .contextMenu { Button("Go to Second View") { goToSecond.toggle() } } } .navigationDestination(isPresented: $goToSecond) { SecondView() } } } struct SecondView: View { var body: some View { VStack { Text("SecondView") } } }
Sep ’23
Reply to Picker with ForEach
import SwiftUI struct ProviderCalendarView: View { @StateObject var viewModel = YearViewModel() @State private var selectedYear = 3 var body: some View { VStack { HStack { Picker(selection: $selectedYear) { ForEach(viewModel.years, id: \.self) { year in Text("\(year)") } } label: { } } } } } class YearViewModel: ObservableObject { @Published var years: [Int] = [] init() { createYears() } func createYears() { let now = Date() for i in 0..<4 { years.append(2023 + i) } } } I don't use Range to create an array in this case. Yet, I still get the same compiler guy.
Aug ’23
Reply to Removing More?
I think I've fixed it. import SwiftUI struct ContentView: View { @State var selectedTab = 0 @State var addTapped = false @State var refresh = false @State var people = [ Person(name: "Alice", systemImage: "person.circle.fill"), Person(name: "Jane", systemImage: "person.circle.fill"), Person(name: "Dave", systemImage: "person.circle.fill"), Person(name: "Susan", systemImage: "person.circle.fill"), Person(name: "Robert", systemImage: "person.circle.fill"), Person(name: "Daniel", systemImage: "person.circle.fill") ] var body: some View { VStack(alignment: .leading, spacing: 0) { ScrollView(.horizontal) { HStack(spacing: 20) { ForEach(0..<people.count, id: \.self) { num in VStack { ... } .foregroundColor(selectedTab == num ? Color.blue : Color.gray) .onTapGesture { self.selectedTab = num } } } }.padding(.horizontal, 10) Spacer() .frame(height: 2) Rectangle().fill(.gray) .frame(height: 1) TabView(selection: $selectedTab) { ForEach(0..<people.count, id: \.self) { num in let person = people[num] Text(person.name) .tag(person.id) } } } .tabViewStyle(.page(indexDisplayMode: .never)) // <<<<<<<<<<<<<<<<<<<<< .onAppear { UITabBar.appearance().isHidden = true } } }
Aug ’23