Post

Replies

Boosts

Views

Activity

Reply to Swift UI backward compatibility
Most, if not all, of the new iOS 16 features in SwiftUI will only be available from iOS 16 onwards. This is what Apple tends to do every release, so you will have to wait for your minimum deployment target to catch up with the version you need features from if you don’t want to have a lot of if-available checks. Saying this, there are some features from earlier versions of SwiftUI that, even though have been replaced, will still work on the latest versions. For example, in iOS 13-14 you would style a List like this: .listStyle(PlainListStyle()) Although in iOS 15 it was reworked to this: .listStyle(.plain) the older approach will still work. Furthermore, NavigationView has only been soft-deprecated so will continue to work as expected on iOS 16. Check the documentation to see the minimum platform deployment information for each API.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’22
Reply to update TabView background color
Because you are using a UIKit API in SwiftUI in an “unnatural“ way, I won’t work as expected. You’re right about it being sort of a one-time thing. Even Apple recommends staying away from this method: In general, you should not rely on implementation details of a framework (including SwiftUI) to achieve specific behaviors in your apps. In iOS 16, SwiftUI does gain a new modifier: toolbarBackground(_:for:). You can use it like this: ... .toolbarBackground(.red, for: .tabBar) I believe it only applies to the current view, so you can change the behavior at different levels of the hierarchy. See the documentation as there is a lot more you can customise now regarding bars.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to How to convert 'Binding<UIImage>' to expected argument type 'UIImage'
Doing this, like you did in the List example, works fine: ForEach($results) { $result in Image(uiImage: result.image) } Because you are passing a Binding of a collection to the data parameter of the ForEach, the content closure expects to be passed a Binding of one of the collection’s elements. This is why you can access this value with the $ prefix and then read the underlying value, in your case ImageData, without it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to macOS SwiftUI: Dropdown Menu in a MenuExtraApp not working?
Controls, like menus and pickers with the menu style, don't work when placed in a view of an NSMenuItem. I believe only simple controls and ones with button-like behaviour do. If you need the menu as it is, and because it would be classed as a complex view, I would recommend using a popover instead. Something like this should work: var statusItem: NSStatusItem? var popover: NSPopover? func applicationDidFinishLaunching(_ aNotification: Notification) {     statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)     statusItem?.button?.image = NSImage(systemSymbolName: "gearshape.circle", accessibilityDescription: "Logo")     statusItem?.button?.action = #selector(showPopover)     let hostingViewController = NSHostingController(rootView: MenuExtraView())     popover = NSPopover()     popover?.contentViewController = hostingViewController     popover?.contentSize = .init(width: 350, height: 400)     popover?.behavior = .transient } @objc func showPopover(_ button: NSButton) {     popover?.show(relativeTo: button.bounds, of: button, preferredEdge: .minY) } If you just need a standard menu for your status item instead of a view, then add an item like this: menu.addItem(withTitle: "Quit", action: #selector(NSApp.terminate), keyEquivalent: "q")
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Missing argument for parameter 'images' in call
Thank you for sharing all the code. The probable cause of your height issue is that you have wrapped the contents of your ImageCard body in a NavigationView. You don't need to do this as you are already embedding it in one in ContentView. Remove the NavigationView from ImageCard to see if this helps. If it doesn't help, which I'm sure it will, then it would be down to the fact that you are setting an explicit height of 200 to the ZStack in ImageCard. I'm not sure how much this affects things but changing this value to a smaller one might make a difference.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22