Post

Replies

Boosts

Views

Activity

Reply to Hiding chevron from list, SwiftUI
Here is a way to mimic a List without chevron, with a ScrollView: ScrollView(.vertical, showsIndicators: true) { ForEach(0..<15) { index in HStack { Spacer() NavigationLink(destination: DestinationView(item: index)) { Text("Navigate \(index) to View 1") } // Text(">") // This would mimic a List's chevron Spacer() } .padding(.vertical, 5) } } .navigationBarTitle("Navigation Links") } } } struct DestinationView: View { var item: Int var body: some View { Text("Destination View for item \(item)") .navigationBarTitle("View", displayMode: .inline) } }
Topic: UI Frameworks SubTopic: SwiftUI
Jun ’24
Reply to My app Xcode SwiftUI
You have probably a free developer license ? If so, you have to rebuild app regularly (I thought it was every week, but may be shorter). The point is that free licence is done to let you learn to develop, not really to build apps to use.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’24
Reply to SwiftUI chart legend overflow
I tried with Xcode 16.0ß and Xcode 15.3, on iOS 17.4 and 18.0 simulators and got a correct result. It is not wrapped but correctly positioned and sized. So I extended your text further more and got a correct result again: And even more, to exceed width limit: ChartData(id: 2, title: "Item 2 With a Long Title and then some more and even some more for a crazy legend length", count: 6, color: .blue), Then it did not work. I used a different modifier to build the legend manually: .chartLegend(alignment: .leading, content: { HStack(alignment: .top, spacing: 5) { ForEach(data) { d in HStack { Text("•") .font(.system(size: 48)) .bold() .foregroundStyle(d.color) Text("\(d.title)") .font(.system(size: 14)) .lineLimit(nil) // Multilines .foregroundStyle(Color.gray) } .frame(width: 125, height: 120) } } }) You can adapt content to better fit your need.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’24
Reply to Data update issue when both parent and child views are @State in SwiftUI
For the first question. You have to use Binding and not State in SubView1: struct SubView1: View { // @State var data: String @Binding var data: String And of course call it appropriately: SubView1(data: $data) With State, you keep the state of the var. With Binding, you reference the parameter passed, so it is updated. In SubView2, you pass directly the parameter, so it is used for display. For your second question, my understanding is that effectively the compiler optimises the views creation. As Subview1 is already created, it can reuse it immediately without creating a new instance.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’24
Reply to I want to limit input on textfield...
You shoals use the onChange on TextField to test on the fly. Do it in onSubmit to test only when you hit return key. If the State var in the TextField is input, you should test if only letters .onChange(of: input) { oldInput, proposedInput in if onlyLetters(proposedInput) { input = proposedInput } else { input = oldInput } } onlyLetters is a func to test the proposed string contains only letters. func onlyLetters(_ s: String) -> Bool { return resultoftest } See here a way to implement: https://stackoverflow.com/questions/60657152/how-to-check-whether-string-only-consists-of-letters-and-spaces-in-swift-5
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’24