This question already has answers here:
Implement dark mode switch in SwiftUI App
(9 answers)
Closed 1 year ago.
Is it possible in SwiftUI to force a View to use light or dark mode — like overrideUserInterfaceStyle in UIKit does?
.colorScheme() is deprecated does not work with the background well.
.preferredColorScheme() is the way now. Does the job with the background too.
TestView1()
.preferredColorScheme(.dark)
TestView2()
.preferredColorScheme(.light)
Developer docs for .preferredColorScheme()
Use .colorScheme modifier, like
TestView1()
.colorScheme(.dark)
TestView2()
.colorScheme(.light)
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 months ago.
Improve this question
How do I remove this icon?
I am using very simple code; just navigation view
As mentioned in the comments by #Nirav D, this button is used to toggle the sidebar visibility.
iOS 16 & above
In iOS 16, Apple gave Navigation a big refresh:
Introducing NavigationStack(which is probably what you want), it is used to present a view allowing the user to navigate using NavigationLink as you would on an iPhone.
Introducing NavigationSplitView(which is what you’re seing in the simulator right now), it is used to present a menu (sidebar) that can present detail views. You can have up to 3 columns.
Deprecating NavigationView, from now on you have to use the above containers as NavigationView will be obsoleted in a future iOS release.
iOS 15 & below
In versions earlier than 16, you have to use NavigationView. NavigationView accepts navigationViewStyle, the default style on iPhone is StackNavigationViewStyle where the content is presented in one column. However, on iPad in order to maximise the use of screen estate, SwiftUI sets the default style to ColumnNavigationViewStyle that presents the content in columns (Master -> Detail…).
If you mean to use a single column: you must use either NavigationStack or NaigationView with .navigationViewStyle(.stack);
If you have to use multiple columns & still hide the button: use .navigationBarHidden(true) on the sidebar view, or .toolbar(.hidden, for: .navigationBar) for iOS 16+.
For more info, check: Navigation & The SwiftUI cookbook for navigation
I would like to add a sound effect when a button is pressed in my app for SwiftUI. The button has another feature, but I just want to add a sound effect. I have found information for previous versions of Xcode using UIkit, but I'm not understanding how to do it in SwiftUI.
Edit: I'm very new to programming if that explains my lack of knowledge.
from answer:
Play reminder sound SwiftUI
you can use this simple method:
import AVFoundation
AudioServicesPlaySystemSound(1026)
where the number 1026 is the SystemSound id.
Is it possible to create Xcode widget in Xcode 12 but without the use of SwiftUI and instead use XIB files to construct the Widget UI?
Widget protocol is only available in SwiftUI framework, so you can only create widgets using SwiftUI.
https://developer.apple.com/documentation/swiftui/widget
Update
You can't use UIKit views wrapped in UIViewRepresentable within SwiftUI for Widgets, It will appear blank.
https://developer.apple.com/forums/thread/653471
No, due to performance and battery life concerns, WidgetKit only works with SwiftUI.
https://developer.apple.com/documentation/widgetkit
You configure the widget with a timeline provider, and use SwiftUI views to display the widget’s content. The timeline provider tells WidgetKit when to update your widget’s content.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have an image 32x32 and I want to fill the whole screen with many images
So I thought I could use ForEach but it doesn't seem to work
ForEach(0..<5) {_ in
Image("myImage")
}
this code creates 5 previews instead of 5 images
The problem is that you need to embed the code inside a Vstack or an Hstack.
That way it will know how to create those images (vertically or horizontally)
Vstack(spacing: 0) {
ForEach(0..<5) {_ in
return Image("myImage")
}
}
You need to use VStack or HStack You can't do that. For more info just take a look on the Apple Documentation. Here in Make the List Dynamic you will get the information.
I have a SwiftUI app in which I would like to show the "WorkOut" and "Activity" icons and launch those apps when the respective icon is tapped.
Is this possible in WatchOS6 & SwiftUI?
I know this "can I launch another app from within my app" question has been asked before for iOS or WatchOS but the answers seem old and I was hoping that this is now possible in WatchOS 6.
Thanks!
Gerard
MKMapItem has a method openInMaps() that you can use to open the Maps app.
I don't think there is an equivalent for the Workout/Activity apps.
Also, I seems like using their icons is against the guidelines. You can only use the rings.
https://developer.apple.com/design/human-interface-guidelines/healthkit/overview/