Semi-transparent (blurry like VisualEffectView) of the view behind the current view

The Apple way Investigating on the view hierarchy shows that Apple is using UIKit and UIVisualEffectViewfor this reason. You can define a VisualEffectView with just 5 lines of code: struct VisualEffectView: UIViewRepresentable { var effect: UIVisualEffect? func makeUIView(context: UIViewRepresentableContext<Self>) -> UIVisualEffectView { UIVisualEffectView() } func updateUIView(_ uiView: UIVisualEffectView, context: UIViewRepresentableContext<Self>) { uiView.effect = effect } … Read more

SwiftUI – make sure to publish values from the main thread (via operators like receive(on:)) on model updates

Just put @MainActor before defining your class that is supposed to act in the main thread. And it’s so simple in terms of using new Swift concurrency. @MainActor class DocumentsViewModel: ObservableObject { … } There’s a lot of information about that in new WWDC 2021 videos or articles like that: Using the MainActor attribute to … Read more

How to detect whether targetEnvironment is iPadOS in SwiftUI?

I use this in my code: private var idiom : UIUserInterfaceIdiom { UIDevice.current.userInterfaceIdiom } private var isPortrait : Bool { UIDevice.current.orientation.isPortrait } Then you can do this: var body: some View { NavigationView { masterView() if isPortrait { portraitDetailView() } else { landscapeDetailView() } } } private func portraitDetailView() -> some View { if idiom … Read more

Remove top padding from List

Firstly, I would say that GroupedListStyle is working as intended. On iOS, the grouped list style displays a larger header and footer than the plain style, which visually distances the members of different sections. You say you have tried this, but it does work for me (Xcode 12.5.1): List { … } .onAppear(perform: { UITableView.appearance().contentInset.top … Read more

How to create a simple Binding for previews

You can use .constant(VALUE) in your Previews, no need to create a @State. /// A value and a means to mutate it. @propertyWrapper public struct Binding<Value> { /// Creates a binding with an immutable `value`. public static func constant(_ value: Value) -> Binding<Value> } e.g. TestView(someProperty: .constant(5.0))

Mysterious spacing or padding in elements in a VStack in a ScrollView in SwiftUI

If I understand your ultimate goal, it’s to have each row bordered above by a dotted line, with no padding between them, like this: In that case, IMO you should put the lines in a background. For example: ScrollView { VStack(alignment: .leading) { ForEach(self.elements, id: \.self) { element in HStack { Text(“\(element.index+1)”) .font(.system(.caption, design: .rounded)) … Read more

How to disable NavigationView push and pop animations

Xcode 11.3: Right now there is no modifier to disable NavigationView animations. You can use your struct init() to disable animations, as below: struct ContentView : View { init(){ UINavigationBar.setAnimationsEnabled(false) } var body: some View { NavigationView { VStack { NavigationLink(“Push Me”, destination: Text(“PUSHED VIEW”)) } } } }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)