Add buttons to Titlebar/Toolbar next to triple-dot-menu in macCatalyst in SwiftUI - swiftui

I am trying to create a toolbar for my macCatalyst app in SwiftUI.
On Mac my toolbar should be in the same line as the tripleDotMenu (red, orange, green).
Next to it I want to have my different buttons (see the first image)
I managed removing my titlebar using:
.withHostingWindow { window in
#if targetEnvironment(macCatalyst)
if let windowScene = window?.windowScene as? UIWindowScene {
windowScene.titlebar?.toolbar = nil
windowScene.titlebar?.titleVisibility = .hidden
}
#endif
}
But I can see that the titlebar is just invisible and not gone (image 2). I am not sure how can can get buttons in the top bar...
Developing for macOS it happened automatically..
Can someone help me please? A solution in SwiftUI would be amazing.

I have an iOS/MacCatalyst app, using Swift, not SwiftUI. As soon as I started using Xcode 14, and running on macOS 13 (Ventura), my macCatalyst apps showed the navigation bar menu inline with the 3 dots menu as you say you get for your macOS app. What Xcode and macOS are you using?
There are some bugs with the new inline navigation menu so I've actually reverted back to the previous menu bar style for macCatalyst which has it below the 3 dots section. I did this by inserting
self.navigationController?.navigationBar.preferredBehavioralStyle = .pad

Related

swiftui picker how to hide up down arrows (ios16)

Is there a good way to hide the up down arrows in the picker default style. I am using ios 16. It seems that the older version does not have such arrows.
Also, is there a setting to set the picker's background to the same style as the datepicker in the image without manually setting the background and radious?
I have been struggling on this small feature and tried googling for a few hours but no luck. Any idea will be appreciated
The suggested Menu solution works well if you only have a few options. The problem I've experienced with the Menu solution is that if there are very many options the Menu doesn't automatically scroll to the currently selected option the way the Picker does.
The solution I've used is to use ZStack to place an opaque picker on top of a custom view (my "label"). Setting the opacity modifier on the Picker to 0.025 makes it invisible on your device but it will still trigger when you tap it.
This way you get all the native functionality of the Picker (including scrolling to the selected option) and you can make the label look any way you want without having to create your own custom picker.
Here's the code:
ZStack {
// Custom picker label
Text("\(value)")
.font(.title)
.foregroundColor(.blue)
.styleDataEntry(colorScheme: colorScheme) // a custom formatter View extension
// Invisible picker
Picker("", selection: $value) {
ForEach(0 ..< 200) { option in
Text("\(option)").tag(option)
}
}
.pickerStyle(.menu)
.opacity(0.025)
}

SwiftUI small widget is not opening the iOS app on tap

In my widget, I place a header view.
var header: some View {
ZStack {
Link(destination: url) {
Rectangle().fill(Color("WidgetBackground")).frame(height: 36)
Text("Header")
}
}
}
This is a simple text on a colored background.
The url is the urlscheme for my app.
When I tap on the label or on header view, it opens my app on medium and large size widgets.
But on the small size widgets, it didnt open the app, but it flickers and reload the widget.
I also see the flicker happen in medium and large size widgets when I tap on empty spaces other than elements.
I have no clue , why this flicker happens.
Based on documentation, interacting on widget should open the app, without any extra effort.
Am I missing something ?
I don’t know why the app doesn’t open (an iOS bug, I guess), but your deeplink won’t work because Link isn’t available in the “small” widget size. You need to set the .widgetURL() modifier on your view instead.

SwiftUI - TabView Light Mode UIColor Appears in Preview, not in Sim or Device

I am using Swift 5.3 on MacOS 11.01 and created a new "Multiplatform" app for iOS 14.2. I created custom color assets for light/dark modes but am having trouble getting the light mode background color to show on my TabView. The TabView dark mode background color appears just fine.
The light mode background color appears perfect in Xcode Preview, but when I run the app in the Sim or on my device, the Tab Bar background color is clear in light mode, but shows the correct color for dark mode.
I use the same color assets for coloring my NavigationView and both the light and dark mode colors appear correctly when the corresponding modes are selected.
Is there something obvious I am missing here with the latest SwiftUI 5.3 and color assets?
I am using the following code within .onAppear in the TabView
UITabBar.appearance().barTintColor = UIColor(named: "barBackground")
Note that "barBackground" is the custom color set I created to add a light/dark mode background colors to both the NavigationView and TabView.
Happy to furnish additional info if this isn't clear. Thanks!
It is a bit late to do it in .onAppear, appearance should be changed definitely before affected view is created, so do it in init
init() {
UITabBar.appearance().barTintColor = UIColor(named: "barBackground")
}

SwiftUI Launchscreen not showing

I'm just starting out with Swift and SwiftUI, so I'm a total beginner. My SwiftUI project came with a LaunchScreen.storyboard which I thought would be nice to use, but I have no idea how. The app loads the initial ContentView.swift, even though I filled the LaunchScreen.storyboard with an image. Is there any place I need to specify the app should load the LaunchScreen first and then go to the ContentView after like, 2 seconds or something?
I suspect it's probably in SceneDelegate.swift, but I don't know.
// Create the SwiftUI view that provides the window contents.
let contentView = ContentView()
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView.environmentObject(model))
self.window = window
window.makeKeyAndVisible()
}
Using XCode 11.2
Thanks in advance for any help!
Edit: It really is a cache issue. I deleted the ~/Library/Developer/Xcode/DerivedData/ModuleCache directory and removed the app from the simulator and test device. Then rebuilt and working! Thanks!

Android show ActionBar without navigation items

I would like to display the ActionBar alone without any navigation buttons(Home, back,etc) which are present at the bottom of the screen.
If I use '#android:style/Theme.NoTitleBar.Fullscreen', then even the ActionBar is not present.
Is there a way to display ONLY the ACTIONBAR without the navigation bar at the bottom?
For hiding the Navigation Bar, which is there only since API 14, see this