swiftui

How to get at a value in a coordinator class of a UIRepresentable?

夙愿已清 提交于 2021-01-28 12:51:10
问题 I am using the charts package to display the elevation, when I tap the chart I get the index of the point and I want to use that index to place a marker on the map above it. I.e locations[index].coordinate. I have the following code and I am trying to pass the index value to my mapView that is also using UIRepresentable to display the map, but I'm having a hard time figuring out how to connect to the publisher. How do I connect the @Published in the Coordinator class to the MapKitView, so

How can I tap the Toggle under a View in SwiftUI?

半腔热情 提交于 2021-01-28 12:48:18
问题 There are two views (Toggle and Button) under a view (Rectangle): struct ContentView: View { @State var val = false var body: some View { ZStack { VStack { Text("Control penetration") .font(.title) Toggle(isOn: $val){EmptyView()} Button(action: { print("Yes! Clicked!") }){ Text("Can you click me???") } } .padding() Rectangle() .fill(Color.green.opacity(0.2)) .allowsHitTesting(false) } } } I use allowsHitTesting() to make the click penetrate to the bottom. But only the Button can respond to

How can I tap the Toggle under a View in SwiftUI?

岁酱吖の 提交于 2021-01-28 12:46:01
问题 There are two views (Toggle and Button) under a view (Rectangle): struct ContentView: View { @State var val = false var body: some View { ZStack { VStack { Text("Control penetration") .font(.title) Toggle(isOn: $val){EmptyView()} Button(action: { print("Yes! Clicked!") }){ Text("Can you click me???") } } .padding() Rectangle() .fill(Color.green.opacity(0.2)) .allowsHitTesting(false) } } } I use allowsHitTesting() to make the click penetrate to the bottom. But only the Button can respond to

SwiftUI TextField Representable not increasing Font Size

左心房为你撑大大i 提交于 2021-01-28 12:09:24
问题 I am using a representable View Controller in my SwiftUI app for Mac. As the default TextField is very limited in SwiftUI (FirstResponder, Placeholder color) I am using a representable. It works fine, however I can not increase the Font Size of the TextField, which does work for the default TextField component for SwiftUI. This is my NSViewController: class TextFieldController: NSViewController { @Binding var text: String var isFirstResponder : Bool = true init(text: Binding<String>,

SwiftUI - Navigation bar colour change not being applied to status bar

时光毁灭记忆、已成空白 提交于 2021-01-28 11:57:47
问题 I have the following: var body: some View { NavigationView { VStack { Text("Hello") }.navigationBarTitle("Edit Profile", displayMode: .inline) .background(NavigationConfiguration { nc in nc.navigationBar.barTintColor = .red nc.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.black] }) }.navigationViewStyle(StackNavigationViewStyle()) } For the configuration of the nav bar i have: struct NavigationConfiguration: UIViewControllerRepresentable { var configuration:

Same array binded to two SwiftUI Views hangs-up App when object deleted

情到浓时终转凉″ 提交于 2021-01-28 11:18:42
问题 I try to build an app in MacOS SwiftUI, where two different subviews of main contentView shows different parts of Axis element: struct ContentView: View { @Binding var document: GlyphDesignerDocument var body: some View { HStack { #warning("if AxesSlidersView is not commented, and Axis will be deleted — program explodes") AxesSlidersView(axes: $document.axes) AxesView(axes: $document.axes, addRows: {document.axes.insert(Axis("z", bounds: 0...1000), at: $0)}, removeRows: {document.axes.remove

Hiding Picker's focus border on watchOS in SwiftUI

天涯浪子 提交于 2021-01-28 11:18:32
问题 I need to use a Picker view but I don't see any options to hide the green focus border. Code: @State private var selectedIndex = 0 var values: [String] = (0 ... 12).map { String($0) } var body: some View { Picker(selection: $selectedIndex, label: Text("")) { ForEach(0 ..< values.count) { Text(values[$0]) } } .labelsHidden() } 回答1: The following extension puts a black overlay over the picker border. Result Code extension Picker { func focusBorderHidden() -> some View { let isWatchOS7: Bool = {

SwiftUI: Dark mode not detected when testing on device

[亡魂溺海] 提交于 2021-01-28 11:12:41
问题 I'm am trying to achieve dark mode within my iOS application using SwiftUI: simple test would be to change the background colour. I have set up my colour set as seen below: ContentView.swift: import SwiftUI struct ContentView : View { @EnvironmentObject var session: SessionStore func getUser () { session.listen() } var body: some View { Group { if (session.session != nil) { VStack { WelcomeView() .background(Color("bg")) .edgesIgnoringSafeArea(.all) } } else { VStack { SigninView().transition

SwiftUI drag from one list to another list

青春壹個敷衍的年華 提交于 2021-01-28 10:14:56
问题 I am trying to drag and drop between to Lists. What I have tried: I have found a solution doing it in UIKIt and the using UIViewControllerRepresentable. But that is not what i want. The other solution was using .onDrag {} on list, but that worked on iPad and didn't work on iPhone. How to move items between two Lists on iPhone? 回答1: check this out: BUT -> as you wrote, it works NOT with list (just on iPad), with VStack you can drag from left to right or right to left. import SwiftUI struct

SwiftUI - picker is having freezing when selecting after keyboard is up

╄→尐↘猪︶ㄣ 提交于 2021-01-28 09:51:45
问题 I have a picker: Section(header: Text("About you")) { TextField("About you", text: $profileViewModel.bio) Picker(selection: $profileViewModel.education, label: Text("Education Level")) { ForEach(Education.levels, id: \.self) { level in Text(level).tag(level) } } TextField("Occupation", text: $profileViewModel.occupation) } When I click on the text field, the keyboard appears, which is fine, but when i click on the picker it takes me to the new screen to pick the value and return to the form.