Post

Replies

Boosts

Views

Activity

Reply to change color background with button
You don't need to use ZStack if you have a List, as you simply hide the scroll content background, and set the background colour. Your original code didn't really make much sense. You were creating three instances of ScreenColorButtons and setting a @State var in each one, which only applies to that particular instance. You never actually linked the colour of the background with any of the buttons. The following code works. It creates a @State var in the main view containing the buttons, and a @Binding var in the buttons themselves so when you click the button the bound var is updated. import SwiftUI struct ContentView: View { @State private var colorSelected: Color = Color.red var body: some View { List { ScreenColorButtons(colorSelected: $colorSelected, text: "Red", color: .red) ScreenColorButtons(colorSelected: $colorSelected, text: "Green", color: .green) ScreenColorButtons(colorSelected: $colorSelected, text: "Blue", color: .blue) ScreenColorButtons(colorSelected: $colorSelected, text: "Yellow", color: .yellow) ScreenColorButtons(colorSelected: $colorSelected, text: "Pink", color: .pink) ScreenColorButtons(colorSelected: $colorSelected, text: "White", color: .white) ScreenColorButtons(colorSelected: $colorSelected, text: "Gray", color: .gray) ScreenColorButtons(colorSelected: $colorSelected, text: "Black", color: .black) } .background(colorSelected) .scrollContentBackground(.hidden) } } struct ScreenColorButtons: View { @Binding var colorSelected: Color var text: String var color: Color var body: some View{ Button(action: { colorSelected = color print(colorSelected) }, label: { Text(text) }) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to Button to navigate through SwiftUI Views
Well, this is different from what you actually asked us for. You said: "I need my toolBar buttons to navigate to other SwiftUi views", which I showed you how to do. What you actually mean is you want to change the current view. You could have your toolbar view showing on a MainView(), and the contents of the MainView() is changed depending on which button you've pressed, but the toolbar view remains on top. Something like: struct MainView: View { var body: some View { ZStack { ShowView(viewId: 1) ToolbarView(selectedViewId: 1) } } } struct ShowView(): View { var viewId: Int var body: some View { if(viewId == 1) { // HomeView() } else if(viewId == 2) { ... } } }
Nov ’22
Reply to Invalid Intent Info.plist contains an invalid intent
Can you explain what targets you have, and also which files are in each target, please? In my app I had such a struggle with the intents, and I ended up using these targets: Main App, which contains no supported intents, though there is a space for them in the General tab of the target. Widget, which has no "Supported Intents" section. WidgetIntentHandler, containing both of my intents. Watch App, containing the ComplicationIntentHandler. Complications, which has no "Supported Intents" section. ComplicationsIntentHandler, containing the ComplicationIntentHandler. This worked for me. If you aren't using a Watch App you can ignore the last three.
Topic: App & System Services SubTopic: General Tags:
Nov ’22
Reply to Xcode 14.1 Startup storyboard
Have a look here: https://stackoverflow.com/questions/56529488/is-there-any-way-to-use-storyboard-and-swiftui-in-same-ios-xcode-project You may not actually want to use a storyboard at all as SwiftUI is the way forward. Can you try and create your view in SwiftUI instead? The bit where you put Text("Hello, world!") is where you'd put a toolbar etc.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22