swiftui

How to make a semi-transparent Navigation Bar in SwiftUI?

三世轮回 提交于 2021-01-19 05:57:53
问题 I've seen several posts discussing how to make a transparent Navbar in SwiftUI, but none on how to make a semi-transparent one, which is surprising to me as its a very common patter on Apple's default apps. For example the Notes app: You can see the drawing through the NavBar. Anyone know how to do this, ideally in a way which works in light/dark mode? 回答1: Maybe you just need to add translucency settings in your SwiftUI view init() { UINavigationBar.appearance().isTranslucent = true }

Why does this SwiftUI Picker code not work?

≯℡__Kan透↙ 提交于 2021-01-19 05:56:29
问题 Xcode: 11.2.1 The code below is for a simple form with two components; a Picker (to select a letter) and a Text (to display the selected letter). The code compiles and runs but, when a letter is selected it does not appear in the "Selected..." text. In addition, Xcode displays a (spurious?) run time warning the first time (only) a letter is selected.. struct ContentView: View { @State private var letter = "" private let letters = ["Alpha", "Bravo", "Charlie"] var body: some View {

Why does this SwiftUI Picker code not work?

北城余情 提交于 2021-01-19 05:55:02
问题 Xcode: 11.2.1 The code below is for a simple form with two components; a Picker (to select a letter) and a Text (to display the selected letter). The code compiles and runs but, when a letter is selected it does not appear in the "Selected..." text. In addition, Xcode displays a (spurious?) run time warning the first time (only) a letter is selected.. struct ContentView: View { @State private var letter = "" private let letters = ["Alpha", "Bravo", "Charlie"] var body: some View {

How to change the background color for a Form in SwiftUI?

与世无争的帅哥 提交于 2021-01-18 07:45:10
问题 I wanna change that "light gray" background color for a form, but .foregroundColor(Color.blue) and .background(Color.blue) does not seem to work struct ContentView : View { @State var value = "" var body: some View { Form { Section(header: Text("First Name")) { TextField($value) } Section(header: Text("Last Name")) { TextField($value) } }.foregroundColor(Color.blue) } } 回答1: A Working Solution: All SwiftUI's List s are backed by a UITableView in iOS. so you need to change the background color

SwiftUI Dismiss Multiple Modal Sheets

余生颓废 提交于 2021-01-18 04:18:17
问题 I am using .sheet(isPresented: self.$showModal) in my root view to present a modal. Within the modal, I am using NavigationView to take the user through various pages (for a user profile builder). In the last page of my navigation stack, I am using @Environment(\.presentationMode) var presentationMode and a button which calls self.presentationMode.wrappedValue.dismiss() to dismiss the modal. However, this only dismisses the last page in the navigation stack, and I just end up at the previous

SwiftUI Dismiss Multiple Modal Sheets

怎甘沉沦 提交于 2021-01-18 04:15:45
问题 I am using .sheet(isPresented: self.$showModal) in my root view to present a modal. Within the modal, I am using NavigationView to take the user through various pages (for a user profile builder). In the last page of my navigation stack, I am using @Environment(\.presentationMode) var presentationMode and a button which calls self.presentationMode.wrappedValue.dismiss() to dismiss the modal. However, this only dismisses the last page in the navigation stack, and I just end up at the previous

How to disable vertical scroll in TabView with SwiftUI?

巧了我就是萌 提交于 2021-01-17 07:57:22
问题 I have set up a TabView in my application, so that I can swipe horizontally between multiple pages, but I also have an unwanted vertical scroll that may appear, with a bounce effect so. How can I disable this vertical scroll? My code: struct ContentView: View { @State private var currentTabIndex: Double = 0 var body: some View { VStack { TabView(selection: $currentTabIndex) { Text("Text n°1") .tag(0) Text("Text n°2") .tag(1) } .border(Color.black) .tabViewStyle(PageTabViewStyle

Uploading an Image instead of an UIImage to Firestore

这一生的挚爱 提交于 2021-01-16 04:14:56
问题 Using Swift 5.0 / SwiftUI 2.0 One method available when uploading an UIImage to Firestore is jpegData(compressionQuality: Double) which essentially makes the whole process of fetching the saved image a lot faster. Is there any equivalent for Image yet or any other viable workarounds or its as simple as either UIImage or poor UX 回答1: struct ContentView: View { //Here @State var uiImage: UIImage? var body: some View { VStack { if uiImage != nil { Image(uiImage: uiImage!) } Button(action: {

@State vs @ObservableObject - which and when?

守給你的承諾、 提交于 2021-01-15 22:22:21
问题 I'm currently getting familiar with SwiftUI and Combine frameworks. And I'm not really getting the difference between these two approaches. When we have to keep track of some data (say, a list of tasks), we can declare a @State variable, and it's change will automatically send notification and update current view. However, it looks like it can also be done this way: class TaskList: ObservableObject{ //a list that's going to be modified and updated on different occasions @Published var list:

@State vs @ObservableObject - which and when?

大城市里の小女人 提交于 2021-01-15 22:22:08
问题 I'm currently getting familiar with SwiftUI and Combine frameworks. And I'm not really getting the difference between these two approaches. When we have to keep track of some data (say, a list of tasks), we can declare a @State variable, and it's change will automatically send notification and update current view. However, it looks like it can also be done this way: class TaskList: ObservableObject{ //a list that's going to be modified and updated on different occasions @Published var list: