swiftui

SwiftUI | Picker - Change selected row color

拟墨画扇 提交于 2021-02-10 14:32:55
问题 I want to change the color of the selected row. As you may see, by default it has this light gray color. I have no idea how to do that since I have found no way to access this row at all. Is there any way to do that? Demo code: struct ContentView: View { var data = Array(0...20).map { "\($0)" } @State private var selected = 0 var body: some View { VStack { Picker("", selection: $selected) { ForEach(0 ..< data.count) { Text(data[$0]) } } } } } A UIKit answer would also be welcomed since I have

Remove space NavigationTitle but not the back button

十年热恋 提交于 2021-02-10 14:13:49
问题 I want to remove the NavigationTitle Space without removing the back button. I have already tried this: .navigationBarItems(trailing: NavigationLink(destination: Preferences(viewModel: viewModel).navigationBarHidden(true)) { Image(systemName: "gear") .font(.title2) } ) but that removes the back button as well. 回答1: Standard Back button cannot be shown without navigation bar, because it is navigation item, so part of navigation bar. I assume you just need transparent navigation bar. Here is

Remove space NavigationTitle but not the back button

微笑、不失礼 提交于 2021-02-10 14:11:14
问题 I want to remove the NavigationTitle Space without removing the back button. I have already tried this: .navigationBarItems(trailing: NavigationLink(destination: Preferences(viewModel: viewModel).navigationBarHidden(true)) { Image(systemName: "gear") .font(.title2) } ) but that removes the back button as well. 回答1: Standard Back button cannot be shown without navigation bar, because it is navigation item, so part of navigation bar. I assume you just need transparent navigation bar. Here is

Remove space NavigationTitle but not the back button

痴心易碎 提交于 2021-02-10 14:09:21
问题 I want to remove the NavigationTitle Space without removing the back button. I have already tried this: .navigationBarItems(trailing: NavigationLink(destination: Preferences(viewModel: viewModel).navigationBarHidden(true)) { Image(systemName: "gear") .font(.title2) } ) but that removes the back button as well. 回答1: Standard Back button cannot be shown without navigation bar, because it is navigation item, so part of navigation bar. I assume you just need transparent navigation bar. Here is

How to display an image where the user taps? SwiftUI

巧了我就是萌 提交于 2021-02-10 13:59:29
问题 I am making a mining tapping game and I want to display a hammer wherever the user taps. I mean, wherever the user taps the hammer image will stay on for one second. Is there a way to do it? My example code is below: struct Level1: View { @State var tapScore = 0 @State var showingMinedHammer = false func showMinedHammer() { self.showingMinedHammer = true DispatchQueue.main.asyncAfter(deadline: .now() + 1) { self.showingMinedHammer = false } } func mine() { tapScore += 1 showMinedHammer() }

SwiftUI: Build View from bottom alignment in scrollView

泄露秘密 提交于 2021-02-10 13:12:01
问题 Is there a way to build UI elements in SwiftUI inside scroll view with bottom Alignment? My use case: I have a screen where the screen has Spacer ( What ever is left after allocating below elements ) LogoView Spacer() - 30 Some Text - 4/5 lines Spacer() - 50 (this will be calculated off of GR size Height) HStack with Two Button - This should be pinned to bottom of view / ScrollView I would like to know how Can I pin the HStack view to ScrollView Bottom I've replicated my setup and reproduced

SwiftUI: Build View from bottom alignment in scrollView

ぐ巨炮叔叔 提交于 2021-02-10 13:05:09
问题 Is there a way to build UI elements in SwiftUI inside scroll view with bottom Alignment? My use case: I have a screen where the screen has Spacer ( What ever is left after allocating below elements ) LogoView Spacer() - 30 Some Text - 4/5 lines Spacer() - 50 (this will be calculated off of GR size Height) HStack with Two Button - This should be pinned to bottom of view / ScrollView I would like to know how Can I pin the HStack view to ScrollView Bottom I've replicated my setup and reproduced

Check state of Option-Key in SwiftUI (macOS)

北战南征 提交于 2021-02-10 12:43:01
问题 I'm looking for a way to check the state of the option-key in SwiftUI on macOS. I.e. depending on whether the option key is pressed or not I want to perform different actions in the .onTapGesture closure. 回答1: macOS-only SwiftUI has .modifiers modifier to specify EventModifiers , so your case is covered like in below example: Rectangle() .fill(Color.yellow) .frame(width: 100, height: 40) .gesture(TapGesture().modifiers(.option).onEnded { print("Do anyting on OPTION+CLICK") }) .onTapGesture {

Check state of Option-Key in SwiftUI (macOS)

∥☆過路亽.° 提交于 2021-02-10 12:40:44
问题 I'm looking for a way to check the state of the option-key in SwiftUI on macOS. I.e. depending on whether the option key is pressed or not I want to perform different actions in the .onTapGesture closure. 回答1: macOS-only SwiftUI has .modifiers modifier to specify EventModifiers , so your case is covered like in below example: Rectangle() .fill(Color.yellow) .frame(width: 100, height: 40) .gesture(TapGesture().modifiers(.option).onEnded { print("Do anyting on OPTION+CLICK") }) .onTapGesture {

Check state of Option-Key in SwiftUI (macOS)

五迷三道 提交于 2021-02-10 12:40:07
问题 I'm looking for a way to check the state of the option-key in SwiftUI on macOS. I.e. depending on whether the option key is pressed or not I want to perform different actions in the .onTapGesture closure. 回答1: macOS-only SwiftUI has .modifiers modifier to specify EventModifiers , so your case is covered like in below example: Rectangle() .fill(Color.yellow) .frame(width: 100, height: 40) .gesture(TapGesture().modifiers(.option).onEnded { print("Do anyting on OPTION+CLICK") }) .onTapGesture {