swiftui

SwiftUI: ListItem gestures

家住魔仙堡 提交于 2020-11-30 12:39:31
问题 Target is a modification with the following behavior: (but only with 2 buttons - 1 on the left side, 1 on the right) Behavior: short swipe shows the buttons and gives the user the ability to click it. strong long swipe presses button. ability to use 2 finger gesture Minimal reproducible example: import SwiftUI public extension View { func SwiperizeItem(closureL: @escaping () -> (), closureR: @escaping () -> ()) -> some View { self.modifier( SwiperizeItemModifier(closureL: closureL, closureR:

SwiftUI: ListItem gestures

纵然是瞬间 提交于 2020-11-30 12:39:25
问题 Target is a modification with the following behavior: (but only with 2 buttons - 1 on the left side, 1 on the right) Behavior: short swipe shows the buttons and gives the user the ability to click it. strong long swipe presses button. ability to use 2 finger gesture Minimal reproducible example: import SwiftUI public extension View { func SwiperizeItem(closureL: @escaping () -> (), closureR: @escaping () -> ()) -> some View { self.modifier( SwiperizeItemModifier(closureL: closureL, closureR:

SwiftUI: ListItem gestures

岁酱吖の 提交于 2020-11-30 12:39:20
问题 Target is a modification with the following behavior: (but only with 2 buttons - 1 on the left side, 1 on the right) Behavior: short swipe shows the buttons and gives the user the ability to click it. strong long swipe presses button. ability to use 2 finger gesture Minimal reproducible example: import SwiftUI public extension View { func SwiperizeItem(closureL: @escaping () -> (), closureR: @escaping () -> ()) -> some View { self.modifier( SwiperizeItemModifier(closureL: closureL, closureR:

How to open file dialog with SwiftUI on platform “UIKit for Mac”?

耗尽温柔 提交于 2020-11-30 12:34:48
问题 NSOpenPanel is not available on platform "UIKit for Mac": https://developer.apple.com/documentation/appkit/nsopenpanel If Apple doesn't provide a built-in way, I guess someone will create a library based on SwiftUI and FileManager that shows the dialog to select files. 回答1: Here's a solution to select a file for macOS with Catalyst & UIKit In your swiftUI view : Button("Choose file") { let picker = DocumentPickerViewController( supportedTypes: ["log"], onPick: { url in print("url : \(url)") }

Selected list row's background remains grey (selected) after navigating back in List (SwiftUI). iOS14 + Xcode12

陌路散爱 提交于 2020-11-30 07:42:30
问题 The selected row remains grey after navigating back from the detail view. Happening both on simulator and real device, only on iOS 14. Does anyone know how to remove it so it behaves the same as on iOS 13 (doesn't remain selected)? This is the only code in the project. (No other navigation's or anything). let items = ["item1", "item2"] struct ContentView: View { var body: some View { NavigationView { VStack { Text("Hello") List(items, id: \.self) { item in NavigationLink(destination: Text

Selected list row's background remains grey (selected) after navigating back in List (SwiftUI). iOS14 + Xcode12

旧时模样 提交于 2020-11-30 07:36:47
问题 The selected row remains grey after navigating back from the detail view. Happening both on simulator and real device, only on iOS 14. Does anyone know how to remove it so it behaves the same as on iOS 13 (doesn't remain selected)? This is the only code in the project. (No other navigation's or anything). let items = ["item1", "item2"] struct ContentView: View { var body: some View { NavigationView { VStack { Text("Hello") List(items, id: \.self) { item in NavigationLink(destination: Text

Selected list row's background remains grey (selected) after navigating back in List (SwiftUI). iOS14 + Xcode12

十年热恋 提交于 2020-11-30 07:35:52
问题 The selected row remains grey after navigating back from the detail view. Happening both on simulator and real device, only on iOS 14. Does anyone know how to remove it so it behaves the same as on iOS 13 (doesn't remain selected)? This is the only code in the project. (No other navigation's or anything). let items = ["item1", "item2"] struct ContentView: View { var body: some View { NavigationView { VStack { Text("Hello") List(items, id: \.self) { item in NavigationLink(destination: Text

How to remove the line separators from a List in SwiftUI without using ForEach?

可紊 提交于 2020-11-30 02:19:12
问题 I have this code to display a list of custom rows. struct ContentView : View { var body: some View { VStack(alignment: .leading) { List(1...10) {_ in CustomRow() } } } } However, I want to remove the line on each row. I tried not using List and instead using ForEach inside ScrollView but it completely removes all the styling including its padding and margins. I just want to remove the lines and nothing else. Please help, thank you. 回答1: iOS 14: you may consider using a LazyVStack inside a

Unable to Save Picker Result to UserDefaults

。_饼干妹妹 提交于 2020-11-29 21:27:40
问题 I am trying to save the result of a picker to user defaults. The user default save operation occurs in the class UserData via method saveBase. I have tried a similar technique successfully with a button but my call after the picker gives the famous error: Type '()' cannot conform to view. struct aboutView: View { @EnvironmentObject var userData: UserData @State private var baseEntry: Int = 0 let base = ["Level 1", "Level 2","Level 3","Level 4"] var body: some View { Text("comment") Text(

Unable to Save Picker Result to UserDefaults

喜你入骨 提交于 2020-11-29 21:21:05
问题 I am trying to save the result of a picker to user defaults. The user default save operation occurs in the class UserData via method saveBase. I have tried a similar technique successfully with a button but my call after the picker gives the famous error: Type '()' cannot conform to view. struct aboutView: View { @EnvironmentObject var userData: UserData @State private var baseEntry: Int = 0 let base = ["Level 1", "Level 2","Level 3","Level 4"] var body: some View { Text("comment") Text(