swiftui

How SwiftUI sets the spacing between the underline and the text?

匆匆过客 提交于 2020-12-06 11:22:10
问题 Code to set underline,I want to make the space between the text and the underline larger. Text("underline text") .underline() 回答1: Underline is a font feature, you can do custom under just by drawing line anywhere needed var body: some View { HStack { Text("Before") Text("underline text") .overlay( Rectangle().frame(height: 1).offset(y: 4) , alignment: .bottom) Text("after.") } } 回答2: You could create a custom view that takes the text and underline padding as parameters struct UnderlinedText:

Swift ui macos background transparent TextField

雨燕双飞 提交于 2020-12-06 09:03:34
问题 As you can see from the image I have a TextField and after list . The list has a transparent background, I'm using .listStyle(SidebarListStyle()) . But how do I get a transparent background where the TextField is located. Code: VStack(alignment: .leading, spacing: 0) { TextField("Username", text: $username) .padding(.leading, 20) .padding(.trailing, 20) .background( RoundedRectangle(cornerRadius: 5) .fill(Color.white.opacity(0.3) ) .padding(.leading, 20) .padding(.trailing, 20) ) .padding(

How does UIViewRepresentable size itself in relation to the UIKit control inside it?

こ雲淡風輕ζ 提交于 2020-12-06 06:49:06
问题 I'm totally perplexed and unable find documentation on how to wrap a UIKit component and have it be sized correctly. Here's the simplest example, wrapping a UILabel: public struct SwiftUIText: UIViewRepresentable { @Binding public var text: String public init(text: Binding<String>) { self._text = text } public func makeUIView(context: Context) -> UILabel { UILabel(frame: .zero) } public func updateUIView(_ textField: UILabel, context: Context) { textField.text = text textField.textColor =

Make TextField wrap it content in SwiftUI

百般思念 提交于 2020-12-06 06:39:55
问题 I'm trying to implement such component TextField (5 000) and Text (PLN) together should be centered horizontally. On entering new digit's, Text (PLN) should be dismissed. I think I have to combine this two views in to one container and center in, something like HStack { TextField() Text("PLN") } .frame(alignment: .center) But TextField is taking all possible width. How could I handle it, or probably another solution. 回答1: Here is possible approach with dynamically sized TextField . Note:

SwiftUI - How to remove white background behind List that is styled with SidebarListStyle, in portrait mode

我只是一个虾纸丫 提交于 2020-12-05 11:58:05
问题 I have a list styled with SidebarListStyle (new in iOS 14) inside a NavigationView . struct ContentView: View { let data = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen"] var body: some View { NavigationView { List { Section(header: Text("Section")) { ForEach(data, id: \.self) { word in Text(word) } } } .listStyle(SidebarListStyle()) .navigationBarTitle(Text("Title"), displayMode: .large) } } } The problem is that

@State not updating in SwiftUI 2

青春壹個敷衍的年華 提交于 2020-12-05 11:17:28
问题 Anybody see problems with @State variables not updating in SwiftUI 2 in Xcode 12b? The problem code is in the contextMenu buttons. The showSheet var is toggled to true but the sheetItem value is not changed. This same code worked in SwiftUI 1. I have filed a Feedback, but was wondering if anyone else has seen this problem. Full code: struct ConnectionsView: View { @EnvironmentObject var connectionViewModel : FileDataViewModel<Connection> @State private var editMode = EditMode.inactive @State

SwiftUI - NavigationView title and back button clipped under status bar after orientation change

混江龙づ霸主 提交于 2020-12-05 10:54:06
问题 Whenever I rotate the device to landscape and back again, the top of the NavigationView (including the title and back button) get clipped under the status bar. Edit: Minimal reproducible example: struct ContentView: View { var body: some View { NavigationView { ScrollView { VStack { ForEach(0..<15) { _ in Text("Filler") .frame(maxWidth: .infinity) .background(Color.green) .padding() } } } .navigationBarTitle("Data") } } } As long as the content is scrollable, the glitch happens. I originally

iOS 14 Invalid frame dimension (negative or non-finite)

牧云@^-^@ 提交于 2020-12-05 09:58:00
问题 My App uses GeometryReader with some padding to setup a View frame dimension inside a NavigationView. Since iOS 14 i get the following error message: Invalid frame dimension (negative or non-finite) Here is some example code to test: import SwiftUI struct ContentView: View { let padding:CGFloat = 16.0 var body: some View { NavigationView { GeometryReader { p in Text("Hello, world!") .frame(width: p.size.width - padding) .padding() } } } } struct ContentView_Previews: PreviewProvider { static

iOS 14 Invalid frame dimension (negative or non-finite)

强颜欢笑 提交于 2020-12-05 09:54:42
问题 My App uses GeometryReader with some padding to setup a View frame dimension inside a NavigationView. Since iOS 14 i get the following error message: Invalid frame dimension (negative or non-finite) Here is some example code to test: import SwiftUI struct ContentView: View { let padding:CGFloat = 16.0 var body: some View { NavigationView { GeometryReader { p in Text("Hello, world!") .frame(width: p.size.width - padding) .padding() } } } } struct ContentView_Previews: PreviewProvider { static

SwiftUI conditional view will not animate/transition

杀马特。学长 韩版系。学妹 提交于 2020-12-04 20:58:22
问题 I’m trying to get my views to animate/transition using .transition() on views. I use similar code from here and put .transition() to both conditional views. struct Base: View { @State private var isSignedIn = false var body: some View { Group { if(isSignedIn){ Home().transition(.slide) }else{ AuthSignin(isSignedIn: self.$isSignedIn).transition(.slide) } } } } struct AuthSignin: View { @Binding var isSignedIn: Bool var body: some View { VStack { Button(action: { self.isSignedIn = true }) {