Dismiss sheet SwiftUI

iOS 15+ Starting from iOS 15 we can use DismissAction that can be accessed as @Environment(\.dismiss). There’s no more need to use presentationMode.wrappedValue.dismiss(). struct SheetView: View { @Environment(\.dismiss) var dismiss var body: some View { NavigationView { Text(“Sheet”) .toolbar { Button(“Done”) { dismiss() } } } } }

Is there a way to hide scroll indicators in a SwiftUI List?

Any Indicators (List, scrollView, etc.) you can get rid of showing indicators for all Lists, but with an API of the UITableView. because SwiftUI List is using UITableView for iOS behind the scene: struct ContentView: View { init() { UITableView.appearance().showsVerticalScrollIndicator = false } var body: some View { List(0…100, id: \.self) { item in Text(“hey”) … Read more

SwiftUI Repaint View Components on Device Rotation

Here‘s an idiomatic SwiftUI implementation based on a notification publisher: struct ContentView: View { @State var orientation = UIDevice.current.orientation let orientationChanged = NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification) .makeConnectable() .autoconnect() var body: some View { Group { if orientation.isLandscape { Text(“LANDSCAPE”) } else { Text(“PORTRAIT”) } }.onReceive(orientationChanged) { _ in self.orientation = UIDevice.current.orientation } } } The output of … Read more

How to create Radiobuttons in SwiftUI?

Picker(selection: $order.avocadoStyle, label: Text(“Avocado:”)) { Text(“Sliced”).tag(AvocadoStyle.sliced) Text(“Mashed”).tag(AvocadoStyle.mashed) }.pickerStyle(RadioGroupPickerStyle()) This is the code from the 2019 swiftUI essentials keynote (SwiftUI Essentials – WWDC 2019. Around 43 minutes in the video they show this example. It will look like this:

How to create Radiobuttons in SwiftUI?

Picker(selection: $order.avocadoStyle, label: Text(“Avocado:”)) { Text(“Sliced”).tag(AvocadoStyle.sliced) Text(“Mashed”).tag(AvocadoStyle.mashed) }.pickerStyle(RadioGroupPickerStyle()) This is the code from the 2019 swiftUI essentials keynote (SwiftUI Essentials – WWDC 2019. Around 43 minutes in the video they show this example. It will look like this:

Not Receiving scenePhase Changes

I acknowledge this question is specifically about schenePhase changes, however, on macOS I am not able to receive any .background notifications when a user switches to a different app. The older NotificationCenter strategy works as I expected, on both platforms. I’ll add this to the mix for anyone who is just trying to execute some … Read more

SwiftUI TextField touchable Area

This solution only requires a @FocusState and an onTapGesture and a .background with color, and allows the user to tap anywhere, including the padded area, to focus the field. Tested with iOS 15. struct MyView: View { @Binding var text: String @FocusState private var isFocused: Bool var body: some View { TextField(“”, text: $text) .padding() … Read more

How to have text in shapes in SwiftUI?

Here is what I consider to be a more comprehensive answer. This will work as of Xcode 11.5: Text(question) .fixedSize(horizontal: false, vertical: true) .multilineTextAlignment(.center) .padding() .frame(width: 300, height: 200) .background(Rectangle().fill(Color.white).shadow(radius: 3)) Notes: fixedSize() will let the text wrap (since .lineLimit(nil) no longer is working). You can omit it if you simply want one line of … Read more

Change Tabbed View Bar Color SwiftUI

SwiftUI 1.0 – Using named colors Combining barTintColor and isTranslucent For some reason I wasn’t getting the full color of my named color when I used just barTintColor or even backgroundColor. I had to include isTranslucent too. Here is my named color: Setting Just barTintColor (As you can see, it is slightly faded) Setting Just … Read more

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