Post

Replies

Boosts

Views

Activity

Reply to SwiftUI sheet accentColor
The accentColor(_:) modifier is marked as being deprecated with a message saying this: Use the asset catalog’s accent color or tint(_:) instead. Using either of these methods will result in a sheet using this accent colour. If you still want to use accentColor(_:), just reapply this modifier to the sheet content, as a workaround.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Missing argument for parameter 'images' in call
Missing argument for parameter 'images' in call The problem you have is the ImageCard view has an images parameter that you haven't specified in the NavigationLink label. Consecutive statements on a line must be separated by ';' You also have a closing parenthesis after the NavigationLink which has no matching opening parenthesis; this triggers a syntax error. Replace the contents of your ForEach with this: NavigationLink { LandCard() } label: { ImageCard(images: images) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Missing argument for parameter 'images' in call
Sorry if I didn't make this clear, but your code from before should look like this: ForEach(ImagesList, id: \.id) { images in NavigationLink { LandCard() } label: { ImageCard(images: images) } } Currently you are showing the ImageCard view twice, the second as a NavigationLink, but I assume that you only need it once. On your second problem, the height of the ImageCard depends on how you create it. Can you show the code for the ImageCard view so that we can understand what is causing the issue?
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
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 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 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