Post

Replies

Boosts

Views

Activity

scrollClipDisabled not support Form
Apple introduced a new API scrollClipDisabled to disable clip in List. But it dose not work in Form. What should I do if I want to disable the clip action and show the shadow? Or maybe scrollClipDisabled should support Form too? NavigationStack { Form { Section { Picker("播放速度", selection: $playSpeed) { ForEach(speeds, id: \.self) { speed in Text(String(speed)) } } Picker("最高画质", selection: $mediaQuality) { ForEach(MediaQualityEnum.allCases, id: \.self) { speed in Text(speed.desp) } } Toggle("Hevc优先", isOn: $preferHevc) Toggle("无损音频和杜比全景声", isOn: $losslessAudio) } header: { Text("播放器") } } .scrollClipDisabled() // not work }
1
0
619
Aug ’23
Compare @FocusState will trigger change of it's value
I found a weird problem when I use @FocusState. I need to compare the value of @FocusState and display different View. But I found that compare @FocusState will trigger a change of it's value. The code blow will display two list of buttons. When you select the 2 button in the first list, the right button will display. When I try to move to the right button, the focus will jump to the 1 button in the first list. The reason is focused was changed to 1 when I try to jump to the right button(the value of focused will be nil and then 1). And if I remove the compare code(if focused == 2), it will work fine. I am currently using Xcode beta 6. Not sure if it is a bug in beta version. struct Demo: View { @FocusState var focused: Int? var body: some View { HStack { List { ForEach((1...10), id: \.self) { number in Button { } label: { Text("\(number)") } .focused($focused, equals: number) } } List { if focused == 2 { Button { } label: { Text("Button") } } } } } }
0
0
631
Aug ’23
SwiftUI: Change the button color in hover
I want to use the default button style, and I know we can set the tint to change the background color of a button. But how can I change the color when user hover the button, in macOS or tvOS? The hover button color is still a white with a transparency even it shows other color when not in hover.
1
0
2.2k
Dec ’23
Can not create a View with generic inside an other View
I tried to create a View with generic inside an other View, and it works fine with build and run. But when I tried to review it, Xcode 15.1 showed an error. CompileDylibError: Failed to build AView.swift Compiling failed: cannot find 'SubListView' in scope struct AView: View { struct BView<T: DisplayData>: View { } } I need to move the BView out of AView to fix the issues. I think it is a preview bug as it works well on build and run.
1
0
449
Dec ’23
Set value to @State in init function
I want to pass a value to a property marked with @State, and it doesn't work. struct AView: View { @State private var content: String? var body: some View { Text(content ? "") } init(content: String) { self.content = content } } #Preview { AView(content: "Test") } But if I change the content to non optional, it works well. struct AView: View { @State private var content: String var body: some View { Text(content) } init(content: String) { self.content = content } } #Preview { AView(content: "Test") } I googled for a while and found that I need to use a spacial way to initialize @State property in the first case. init(content: String) { _content = State(initialValue: content) } It works, but why? Is there any difficulty to unified API between optional and non optional @State property?
0
0
466
Dec ’23
Swift Chars chartYScale layout problem
I tried to narrow down the y-axis and use the clipped() to crop the excess. However, the clipped portion is too small, causing some of the chart to render above the x-axis. Is there any way to fix this, or any way to have the framework automatically set the y-axis range based on the data?
2
0
733
Nov ’25
Markdown openURL can not handle property url
I'm trying to render a markdown with a link using Text. If the URL of the link is a static string, then no problem. If the URL is a property, then OpenURLAction gets a string ‘%25@’. I think this may be a bug. struct ContentView: View { let url = "https://www.google.com" var body: some View { Text("[Terms of Service](\(url))") .environment(\.openURL, OpenURLAction(handler: { url in print(url) return .handled })) } }
2
0
100
Mar ’25
tabBarMinimizeBehavior behavior in iOS 26
I'm trying to revamp the player into a floating style like Apple music. I use tabViewBottomAccessory with tabBarMinimizeBehavior. At the time, I noticed an issue that tabViewBottomAccessory would not automatically collapse when the scroll area was small (but still exceeded the screen height). tabViewBottomAccessory can only be automatically collapsed when the scroll area is large enough. Below is the simplest demo. I'm not sure if it's intentional or if it's a bug. Besides, I wonder if we can control it programmatically(expanded/inline)? struct ContentView: View { var body: some View { TabView { Tab("Numbers", systemImage: "number.circle") { List { // 200 works well, but 20 not ForEach(0..<200) { index in Text("\(index)") } } } } .tabBarMinimizeBehavior(.onScrollDown) .tabViewBottomAccessory { HStack { Text("SwiftUI Demo App") } } } }
1
0
147
Dec ’25
Modify the default gradient background of toolbar in iOS26
In the new iOS 26 design, the navigation bar and tab bar will have a dark gradient background. We found that the color of this gradient depends on the background color of the page. For example, in the following page, our background color is green, so the navigation bar and tab bar will change the gradient to green. Is there any way to change this gradient color? I tried .toolbarBackground(.hidden, for: .navigationBar), but does not work。 I tried .toolbarBackground(LinearGradient(colors: [.black.opacity(0.4), .black.opacity(0)], startPoint: .top, endPoint: .bottom), for: .navigationBar), but it looks like the default gradient is the superposition of the gradient I defined, not a replacement.
Topic: UI Frameworks SubTopic: SwiftUI
1
0
122
3w
Import DocC to Xcode
I'm trying to figure out how to build DocC from other frameworks to Xcode's Developer Documentation. I tried using the build documentation command, and it generates the DocC for my project and displays it in the Developer Documentation, but not libraries in the SPM. The code documentation does appear in the Developer Documentation, but the contents of the DocC are not shown.
2
0
971
Jun ’24