Post

Replies

Boosts

Views

Activity

Reply to SwiftUI: forcing focus based on state with TabView and watchOS
I also ran into this problem. I had a custom stepper control in one tab and a Slider in the other tab. I made the custom stepper control respond to the digital crown and made it focusable(). When running the app, going to the second tab worked but returning back to the first froze the whole app. I couldn't get this working properly again. I tried using the new @FocusState property wrapper to control which tab had focus, but that didn't work. I was using Xcode 13, so I didn't know if this was a beta bug.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21
Reply to Button to another View
There are two main ways of showing a new view. Using a NavigationLink to push to a new view: NavigationView { NavigationLink(destination: NewView()) { Text("Show new view") } } // make sure to embed in a NavigationView Showing a sheet or full screen cover (slides up from the bottom) with the new view: @State private var showingNewView = false Button { showingNewView = true } label: { Text("Show new view") } .sheet(isPresented: $showingNewView) { NewView() } Documentation links: NavigationLink Sheet Full screen cover
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21
Reply to Custom Font Picker Accessing UIFont Properties Crashes App
Update: I've managed to narrow down the problem even more. There is a new font family called System Font that I haven't seen before. It contains lots of font names that are replaced by TimesNewRomanPSMT which is what all the dialog appearing in the console is about. For now I have created a new property on UIFont that will remove this font family, and now no more text is outputted in the console. class var filteredFamilyNames: [String] {     var filtered = Self.familyNames     filtered.removeAll { $0 == "System Font" }     return filtered } Is this font family a new thing in iOS 15? Why are there so many fonts inside this family that Core Text can't use?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’21
Reply to Custom Font Picker Accessing UIFont Properties Crashes App
While I am still here, can I ask if there is a better way to get the family name that a particular font is in. The updated version of this method on UIFont works, but it has a cost on performance. When interacting with the font picker, it takes about a second for the UI to update. class func familyName(forFontName fontName: String) -> String {     var familyName = ""    filteredFamilyNames.forEach { family in         fontNames(forFamilyName: family).forEach { font in            if font == fontName {                 familyName = family             }         }     }     return familyName } Thank you to anyone who can help with this matter.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’21
Reply to How to specify different list style in .listStyle() based on current device?
I had this problem before and my answer to your question based off of that would be to create a custom ViewModifier and use @ViewBuilder so you can handle the compilation error message. Something like this should work: struct DeviceAdaptedListStyle: ViewModifier { var isPhone: Bool { ... } @ViewBuilder func body(content: Content) -> some View { if isPhone { content.listStyle(.plain) } else { content.listStyle(.sidebar) } } } extension List { func deviceAdaptedListStyle() -> some View { modifier(DeviceAdaptedListStyle()) } } At the moment, there might be a better solution with Swift 5.5, but I haven't checked.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’21
Reply to SwiftUI List/Form Header Alignment on iOS 15?
I believe the section headers in a list should be aligned with the content in the list rows. This has been updated in iOS 15 for SwiftUI to match how UITableView section headers were being aligned previously. If you still want the other style of header then, as of iOS 15 beta 4, you can apply the headerProminence modifier to a Section. Section("Section Header") { Text("Hello, World!") } .headerProminence(.increased) This will align the header text will the edge of the list. Note: section headers modified in this way may be changed in future betas to be correctly aligned.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’21
Reply to How to make a pop up view?
You should use the popover modifier. This will show a sheet on iPhone and an overlaying view on iPad. Here’s an example: Button("Rules") { presentPopup = true } .popover(isPresented: $presentPopup, arrowEdge: .bottom) { Text("test") .frame(width: 100, height: 100) } Check out the documentation for more information on usage.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’21
Reply to Preferred Actions in Alerts
It seems that, after rereading the new documentation on alert(_:ispresented:actions:message:), you can just add the .keyboardShortcut(.defaultAction) modifier to one of the buttons in the alert's actions to make it the default action and therefore bold.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to Error when previewing on device
After seeing that my feedback report (FB8991275) has a potential fix in Xcode 13, I tried previewing on a device running iOS 15 beta 4 using Xcode 13 beta 4 and unfortunately I am getting the same error message, again. I really hope that this fix will be available in future betas or at least the official release of Xcode 13.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21