Post

Replies

Boosts

Views

Activity

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
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 How to convert NavigationLink tag and selection to value?
By rearranging the way properties are fed into SwiftUI, you can make it fit for the new APIs. Something like this should work: NavigationStack { List(workoutTypes) { workoutType in NavigationLink(workoutType.name, value: workoutType) } .navigationDestination(for: HKWorkoutActivityType.self) { workoutType in SessionPagingView() } } NavigationSplitView { List(workoutTypes, selection: $workoutManager.selectedWorkout) { workoutType in NavigationLink(workoutType.name, value: workoutType) } } detail: { SessionPagingView() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’22
Reply to macOS SwiftUI: Dropdown Menu in a MenuExtraApp not working?
I forgot to add this, but when you do start to target macOS Ventura, menus and pickers will work properly in a MenuBarExtra with the .window style.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’22
Reply to The primary action of Menu cannot triggered
File feedback as this seems to be an issue.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’22
Reply to how to assign to Binding<String>
You can assign a value directly to the variable, like this: url = tempUrl
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Jul ’22
Reply to Problems with NavigationView() and NavigationLink
Can you show us some code that will help to explain why this is happening? It seems like you have multiple NavigationViews each with NavigationLinks that cause this stacked appearance.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to SwiftUI TabView with page style doesn't present dots on watchOS
It might be a bug in watchOS 9. If it’s not, then you can manually control the indicators by adding this parameter to the tab view style: .tabViewStyle(.page(indexDisplayMode: .always))
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to Changing the images and tint of the icons provided by NavigationSplitView
Setting the values in the AccentColor colour set in the asset catalog to your desired tint colour should work. I don’t know if using the tint(_:) modifier works but you could try that too.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to SwiftUI: Bottom sheet from the iPhone "find my" and "maps" app
This is currently a limitation with the new API. I have already filed feedback and I suggest you do too.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to SwiftUI List Separator within NavigationView Problem
The problem was that List was defaulting to a .sidebar list style which caused the separators to be inset as if there was a symbol image there. This could be fixed by manually changing to another list style. This has since been resolved in iOS 16, and the ability to modify separator insets has been added.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’22
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:
Replies
Boosts
Views
Activity
Aug ’22
Reply to largeTitleDisplayMode doesn't work when using UIHostingController
You need to specify that the navigation bar can display large titles, like this: navigationController?.navigationBar.prefersLargeTitles = true
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to How to convert NavigationLink tag and selection to value?
By rearranging the way properties are fed into SwiftUI, you can make it fit for the new APIs. Something like this should work: NavigationStack { List(workoutTypes) { workoutType in NavigationLink(workoutType.name, value: workoutType) } .navigationDestination(for: HKWorkoutActivityType.self) { workoutType in SessionPagingView() } } NavigationSplitView { List(workoutTypes, selection: $workoutManager.selectedWorkout) { workoutType in NavigationLink(workoutType.name, value: workoutType) } } detail: { SessionPagingView() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to largeTitleDisplayMode doesn't work when using UIHostingController
Try changing the part in viewDidLoad to this: addChild(contentView) view.addSubview(contentView.view) contentView.didMove(toParent: self) // add this
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’22
Reply to Handling single selection action in multi-selection SwiftUI Table
Looks like in beta 5 the contextAction modifier has been removed and merged with contextMenu. The new modifier is contextMenu(forSelectionType:menu:primaryAction:).
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’22