I'm trying to replicate the behavior of Apple's own Music and Photos apps where the main navigation is displayed as a Tab Bar when horizontally compact but as a sidebar in a split view when not compact.
I've found sample code (including the Fruita demo) that demonstrates using Tab Bar or Sidebar depending on size class, but it doesn't preserve the detail view state the way Music and Photos do. For example, in Music if you select "Search" and then begin multitasking the "Search" detail view remains visible and stays selected during the transition from Sidebar to Tab Bar or visa versa.
I suspect this may be easier to do manually in UIKit, but I'm kind of surprised it's not the default behavior in SwiftUI. Has anyone been able to replicate the Sidebar/Tab Bar transition behavior of Photos or Music in SwiftUI?
Post
Replies
Boosts
Views
Activity
I'm trying to create a custom button style that encapsulates default background, colors, and font that can be used in a few different contexts by slightly tweaking the layout.
For example, I can add a color background and some default padding:
struct ExampleButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.padding(EdgeInsets(top: 10, leading: 16, bottom: 10, trailing: 16))
.background(Color.red)
}
}
However, if I want to reuse this button style's background, font, and coloring but just change the layout to be the full width of the screen, things don't work as expected.
Button("Hello world") { }
.buttonStyle(ExampleButtonStyle())
.frame(maxWidth: .infinity)
In this case, the Button does stretch to fill the view it's in, but the red colored background stays the same content size + padding. Is there a different way to get the expected behavior, that the styled layout size can be tweaked with additional view modifiers? Or are we just expected to create different ButtonStyles or pass a configuration parameter into the ButtonStyle initializer?
I have run into the issue of trying to use a static library in an iOS app running in the simulator on an M1 (Apple Silicon) mac. However I'm having a difficult time adapting existing recommended solutions to my use-case.
As I understand it, the root cause is that previously iOS simulator targets were always Intel but now on Apple Silicon the simulator targets can also be arm64. The recommended solution is to use XCFramework to better handle the combinations of platform and arch (e.g. iOS simulator + arm64).
I have a cross-platform C library with a Makefile that I have in Xcode as an "External Build System" target. In the Xcode target it calls /usr/bin/make with the following arguments, where it passes relevant build settings from the iOS Framework to this external make task. On Intel-based Macs this has worked to automatically change the arch and SDK depending on the build target chosen in Xcode, e.g. building for simulator or making an archive.
build CONF=$CONFIGURATION CND_PLATFORM=$PLATFORM_NAME IPHONEOS_DEPLOYMENT_TARGET=$IPHONEOS_DEPLOYMENT_TARGET CFLAGS="-arch $PLATFORM_PREFERRED_ARCH -isysroot $SDKROOT -fembed-bitcode"
Where I believe I'm stuck is that, when building for iOS simulator on my M1 MacBook, the $PLATFORM_NAME is correctly set for the simulator but the $PLATFORM_PREFERRED_ARCH still shows x86_64. When the iOS Framework goes to link with the static library produced by this makefile it complains about missing symbols (presumably because it's looking for arm64 symbols).
How can I pass the correct contextual build information to this External Build System (makefile) target for the iOS Simulator on Apple Silicon?
I am wanting to not only surface my content in the system-level Spotlight search results but also to utilize the same index for my in-app search screen. The very few examples or tutorials I could find all craft a CSSearchQuery string using just the "title" attribute. I can't figure out where to look to understand how to search across other attributes.
My most pressing need is to be able to perform a CSSearchQuery looking for a search term in the .htmlContentData attribute. If I search for this term in the system search field it returns results, so I know it's being indexed. However when I use a search query (in my app) like htmlContentData == "someSearchTerm" I get zero results.
This frustration has led to some more general questions like:
How do you know what attribute names are available to use in the search query? Is it just a string literal that's exactly the same as the CSSearchableItemAttributeSet property in Swift? e.g. property .htmlContentData is referred to as "htmlContentData" in the query string?
Also, is there any way to just search across all attributes with CSSearchQuery? Obviously using the system Spotlight search (from Home Screen) you don't have to specify if you're searching the title or htmlContentData, it just finds it in either. Yet for CSSearchQuery I have to know up-front which fields I want to look in?