Post

Replies

Boosts

Views

Activity

Customizing Swipe to Delete Button
Hi, Im trying to customize the button that appear when swiping a for each list for deleting trying to show a red circle and a white trash icon inside it, but instead I get a white empty button ? .swipeActions(edge: .trailing) { Button { deletePatient(patient: patient) } label: { ZStack { Circle() .fill(Color.red) .frame(width: 50, height: 50) Image(systemName: "trash") .foregroundColor(.white) } } .tint(.white) }
Topic: UI Frameworks SubTopic: SwiftUI
3
1
481
Jan ’25
iOS 17.2 Update, Confusing SwiftData Update !
Hi, Before the iOS 17.2 update the saving behavior of SwiftData was very straightforward, by default it saves to persistence storage and can be configured to save in memory only. Now it saves to memory by default and to make it save to persistence storage we need to use modelContext.Save(). But if we don't quit the App the changes will be saved after a while to persistence storage even without running modelContext.Save() ! How confusing can that be for both developer and the user ! Am I missing something here ? -- Kind Regards
3
0
424
Mar ’25
SwiftuI view Error
Hi Im copying the Apple tutorial project for lists and navigation for SWiftUI but Im getting an error although my code is same as Apple project, can some one check please. Error "Cannot find 'landmarks' in scope" Kindest Regards import SwiftUI struct LandmarkRow: View {     var landmark: Landmark     var body: some View {         HStack {             Text(landmark.name)         }     } } struct LandmarkRow_Previews: PreviewProvider {     static var previews: some View {         LandmarkRow(landmark: landmarks[0])     } } import Foundation import SwiftUI import CoreLocation struct Landmark: Hashable, Codable {     var id: Int     var name: String     var park: String     var state: String     var description: String          private var imageName: String     var image: Image {         Image(imageName)     }          private var coordinates: Coordinates          var locationCoordinate: CLLocationCoordinate2D {         CLLocationCoordinate2D (             latitude: coordinates.latitude,             longitude: coordinates.longitude)     }          struct Coordinates: Hashable, Codable {         var latitude: Double         var longitude: Double     }      }
2
0
1k
Oct ’21
Adding multi view to NavigationPath in one go
Hi How can we add multi view to NavigationPath in one go like in code below maybe using something like path.append(mobiles.all) ? where all 3 views of mobiles Array get added at once ? Kindest Regards `struct NavigationPathView: View { var mobiles: [Mobiles] = [.init (name: "iPhone", imageName: "folder", color: .mint), .init (name: "Samsung", imageName: "pin", color: .pink), .init (name: "Mac Pro", imageName: "book", color: .gray)] @State var path = NavigationPath() var body: some View { NavigationStack (path: $path) { List { Section ("Platforms") { Button("Go To Platform") { path.append(mobiles.first!) } Button("Go To Mobile") { path.append(mobiles.last!) } Button("Add All Mobiles") { } } } } .navigationDestination(for: Mobiles.self) {mobile in ZStack { mobile.color.ignoresSafeArea() VStack { Image(systemName: mobile.imageName) Label (mobile.name, systemImage: mobile.imageName) .font(.largeTitle).bold().foregroundColor(.white) Button("Go Home") { path.removeLast(path.count) } } } } } }
2
0
525
Jun ’24
Reducing space between list rows
Hi, However I tried to reduce space between list rows in below code I fail, is there any way to reduce this space ? @State var flag: Bool = false var myList: [String] = ["Hello", "World", "SwiftUI"] var body: some View { VStack(alignment: .leading) { List (myList, id: \.self) { list in Text(list) .border(Color.black) .font(.system(size: 12)) // Smaller font size .frame(maxWidth: .infinity, minHeight: 20, alignment: .leading) // Reduced height .padding(.vertical, 4) // Minimal padding for vertical spacing .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) // Remove insets .listRowSeparator(.hidden) // Hide separator } .listStyle(.plain) } .overlay( RoundedRectangle(cornerRadius: 10) .stroke(sysSecondary.opacity(0.4), lineWidth: 1) ) .frame(width: 220, height:260) .background(.white) .clipShape (RoundedRectangle (cornerRadius: 10)) } }
Topic: UI Frameworks SubTopic: SwiftUI
2
0
457
Sep ’24
Modifying SwiftData Object
Hi, The dataModule in code below is a swiftData object being passed to the view and its property as key path but when trying to modify it I'm getting the error ."Cannot assign through subscript: 'self' is immutable" how to solve this issue ? Kind Regards struct ListSel<T: PersistentModel>: View { @Bindable var dataModule: T @Binding var txtValue: String var keyPath: WritableKeyPath<T, String> var turncate: CGFloat? = 94.0 var image = "" var body: some View { HStack { Text(txtValue) .foregroundColor(sysSecondary) .font(.subheadline) .onChange(of: txtValue) { value in dataModule[keyPath: keyPath] = value } Image(systemName: image) .foregroundColor(sysSecondary) .font(.subheadline) .imageScale(.small) .symbolRenderingMode(.hierarchical) .scaleEffect(0.8) } .frame(width: turncate, height: 20, alignment: .leading) .truncationMode(.tail) } }
2
0
475
Nov ’24
Customizing Tables in SwiftUI
Hi, How to customize tables in SwiftUI its color background for example, the background modifier doesn't work ? how to change separator lines ? rows background colors ? give header row different colors to its text and background color ? Kind Regards
Topic: UI Frameworks SubTopic: SwiftUI
2
0
502
Nov ’24
Multi Platform App
Hi, Suppose I want to create an School management App that have little complex views so I need a three versions of each view one for Mac and one for iPadOS and one for iOS, cause using platform detector on same view and adjusting layout will make things messy. So what's the best way to achieve that ? Separate project to each platform ? maybe Targets which I still don't understand cause modifying a view in any target will be reflected to other targets so what's the best practice here ? Im working with SwiftUI Kind Regards
Topic: UI Frameworks SubTopic: SwiftUI
2
0
338
Jan ’25