Category "swiftui"

SwiftUI conditionally rendering one view or another

struct ContentView: View { @EnvironmentObject var demoModel: DemoModel var body: some View { //this works demoModel.isLoggedIn ? Text("

.onReceive do not work when @Published property is changed [duplicate]

I have a @Published property in ViewModel and .onReceive in View. When my @Published var changes the .onReceive is not even executed. View is

SwiftUI: Animate offset to slide in from off screen

I'm trying to animate in a view the bottom of its parent view. This is relatively easy to do by animating the offset, like so: struct ContentView: View { @

Add border to only 1 button

I have a simple setup where I have 2 buttons and when a user clicks on one of them I want a border to show around it so that they know which one they clicked I

Expand SwiftUI button tap area over the button frame

I read a similar question about that issue. But that only expand the button size use .padding(). The red region in the snapshot is the tappable area. The trai

How to set a custom environment key in SwiftUI?

Creating a custom environment key works, but if I wish to set the value in a view, XCODE doesn't allow it. But the predefined environment values can be set. Wha

SwiftUI - how to copy text to clipboard?

How does one copy the contents of a Text field to the iOS clipboard? I have the following code & want to replace the "print(..)" statement with a statement

SwiftUI isEmpty on StateObject variable always returns true

I'm trying to get a form validation that checks if the value of a TextField isEmpty to disable the save button on that form. However it seems the check for "isE

SwiftUI List is not showing any items

I want to use NavigationView together with the ScrollView, but I am not seeing List items. struct ContentView: View { var body: some View { Navigat

macOS SwiftUI Navigation for a Single View

I'm attempting to create a settings view for my macOS SwiftUI status bar app. My implementation so far has been using a NavigationView, and NavigationLink, but

How to detect keyboard events in SwiftUI on macOS?

How can I detect keyboard events in a SwiftUI view on macOS? I want to be able to use key strokes to control items on a particular screen but it's not clear how

Circle in SwiftUI doesn't show in my iPhone

I have two Circles to show a circle progress bar, one of these is the progress the another one is the background, but the progress circle doesn't show in my iPh

SwiftUI View not updating based on @ObservedObject

In the following code, an observed object is updated but the View that observes it is not. Any idea why? The code presents on the screen 10 numbers (0..<10)

SwiftUI - is it possible to get didSet to fire when changing a @Published struct?

I have just updated to XCode 11.4 and some of my code has stopped working. I have some @Published struct variables in an ObservableObject. Previously, when I up

SwiftUI Binding default value (Argument labels '(wrappedValue:)' do not match any available overloads)

In Swift you can define default values on a struct that can be overwritten on initialization: struct myStruct { var a: Int = 1 } var instance1 = myStruct()

How to get Text width with SwiftUI?

I would like to underline a title with a rectangle that should have the same width as the Text. First I create an underlined text as below: struct Title: View

SwiftUI Drag and Drop files

I am trying to add a "Drag and Drop" gesture / function to my SwiftUI Mac application. I want to drop files from my System/ Desktop into my Application. It is

SwiftUI rotation animation has unexpected translation [duplicate]

I'm trying to animate a spinning "busy" image in a SwiftUI View using standard and consistent online tutorials. The image is square, should b

SwiftUI UIView with Overlay cancels touch

I am stuck on this UI issue, working with SwiftUI and UIView. Basically, overlay stops user interaction to follow through to the UIView. Button(action: { pri

SwiftUI List inside ScrollView

I want to make my List inside a ScrollView so that I can scroll List rows and headers together. But I found that List inside ScrollView isn't working. It shows