Post

Replies

Boosts

Views

Activity

SwiftUI Button has different internal padding depending on label text length
Hi, I noticed some unexpected layout behavior with Button in SwiftUI: the apparent horizontal padding/inset of a Button seems to change depending on the length of its text label. Here is a minimal example: VStack { Button { } label: { Text("我是一段很长的文字") .lineLimit(nil) .frame(maxWidth: .infinity, alignment: .leading) .border(.red) } Button { } label: { Text("我是一段") .lineLimit(nil) .frame(maxWidth: .infinity, alignment: .leading) .border(.red) } } .frame(width: 100) .border(.red) In Preview, the outer VStack has a fixed width of 100pt, and both Button labels use: .frame(maxWidth: .infinity, alignment: .leading) The red border around each Text shows that the label itself is receiving the expected available width. However, the two Buttons appear to have different horizontal insets between the Button's edge and the Text's edge, even though both Buttons are inside the same VStack and have the same layout configuration. In other words, the Button's apparent internal padding seems to depend on the intrinsic width / length of the label: ┌────────────────────┐ │ ┌──────────────┐ │ │ │ Long text │ │ │ └──────────────┘ │ └────────────────────┘ ┌────────────────────┐ │ ┌────────────┐ │ │ │ Short text │ │ │ └────────────┘ │ └────────────────────┘ What I find particularly confusing is that the label itself has: .frame(maxWidth: .infinity) so I would expect both Button labels to occupy the same available width. I'm trying to understand whether this is expected behavior of the default Button style or a consequence of SwiftUI's layout proposal/intrinsic-size system. Specifically: Why does the Button's apparent horizontal padding change based on the label's text length? Does the default Button style intentionally use the label's intrinsic/ideal size when determining its content inset? Is there an official SwiftUI API to specify a fixed horizontal content inset/padding for a Button, independent of the label's intrinsic size? If I want both Buttons to have exactly the same internal horizontal padding, what is the recommended SwiftUI approach? Is there a way to make the Button give its label the full proposed width before applying its own default styling/insets? I'm aware that I can implement a custom ButtonStyle, but I'm specifically wondering whether there is an existing SwiftUI API or modifier intended for controlling this behavior while retaining the system Button style. I'm seeing this behavior in recent versions of SwiftUI and would appreciate any clarification on the intended layout behavior and the recommended solution. Thanks!
0
0
248
1w
Xcode MCP: Is Swift Package dependency management supported?
Hi Apple, I’m exploring the built-in MCP support in Xcode 27 and noticed that the available Xcode MCP tools don’t seem to provide a way for an agent to manage Swift Package dependencies. For example, an agent can inspect and modify source code, build the project, run tests, and diagnose build issues. However, I haven’t found an MCP tool that allows the agent to perform operations such as: Add a Swift Package dependency to an Xcode project Remove a Swift Package dependency Add/remove a package product from a target Change the version/branch/revision requirement of a package dependency For example, I’d like to be able to give an agent an instruction such as: Add https://github.com/xxx/SomePackage.git to the project, use version 1.2.0 or later, and link the SomePackage product to the MyApp target. At the moment, it appears that the agent can identify that the package is missing when compilation fails, but it cannot actually perform the package configuration step through the Xcode MCP tools. Is Swift Package dependency management intentionally not exposed through Xcode MCP at this time? If it is not currently supported, are there plans to expose APIs/tools for managing: Package dependencies Package products Target-package relationships Package version requirements This would be particularly useful for coding agents, since adding a dependency is a common part of an otherwise automated development workflow. I've submitted a request to feedback, the id is FB24676163. Thanks!
0
0
98
1w
How can I prevent Siri Remote Back button from dismissing a fullScreenCover on tvOS?
I'm developing a tvOS application using SwiftUI, and I have a custom video player presented using fullScreenCover. .fullScreenCover(isPresented: $isPlayerPresented) { PlayerView() } I would like to implement the same kind of behavior commonly seen in video players: The player is presented full screen. When the playback controls are visible, pressing the Siri Remote Back button should hide the controls. The player should remain presented. Only when the controls are already hidden should pressing Back dismiss the player. However, I am unable to intercept the Back button before the fullScreenCover is dismissed. I have tried several approaches, including: .onExitCommand { // Handle Back } and handling UIPress / .menu events through UIKit. The problem is that when the Siri Remote Back button is pressed while the view is presented using fullScreenCover, the fullScreenCover is dismissed directly. My custom view does not appear to be able to prevent the dismissal. I also tried placing a custom UIView / UITapGestureRecognizer inside the fullScreenCover to intercept the remote button event, but the presentation is still dismissed. According to the SwiftUI documentation, onExitCommand responds to the tvOS exit command generated by the Menu button, but it does not appear to provide a way to prevent the system from dismissing a fullScreenCover in response to the Siri Remote Back button. I also noticed that interactiveDismissDisabled(_:) does not appear to provide a solution for this particular tvOS behavior. My questions Is the Siri Remote Back button expected to automatically dismiss a SwiftUI fullScreenCover on tvOS? Is there a supported API to intercept the Back button before the fullScreenCover is dismissed? Is there a way to tell SwiftUI that a fullScreenCover should not be dismissed by the Siri Remote Back button? If fullScreenCover is not intended for this use case, what is the recommended way to implement a custom full-screen video player that needs to control Back-button behavior? The desired behavior is essentially: Back button ↓ Are playback controls visible? ├── Yes → hide controls, keep player presented └── No → dismiss player I would appreciate any guidance on the intended tvOS API or recommended architecture for implementing this behavior. Thanks!
1
0
694
1w
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
207
Jan ’26
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
227
Dec ’25
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
898
Nov ’25
Debug Failed in Xcode Simulator
I can‘t use breakpoints on the simulator after updating Xcode and the simulator. I can use breakpoints on a physical iPhone. I tired to download other iOS simulator version, but still not working. Both SwiftUI and UIKit not working. Xcode version: 16.2 SDK version: 18.2 (22C146) Simulator version: 18.3.1 (22D8075) Mac OS version: 15.4 Beta Couldn't find the Objective-C runtime library in loaded images. Message from debugger: The LLDB RPC server has crashed. You may need to manually terminate your process. The crash log is located in ~/Library/Logs/DiagnosticReports and has a prefix 'lldb-rpc-server'. Please file a bug and attach the most recent crash log.
49
63
17k
Apr ’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
153
Mar ’25
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
1k
Jun ’24
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
509
Dec ’23
SwiftUI Button has different internal padding depending on label text length
Hi, I noticed some unexpected layout behavior with Button in SwiftUI: the apparent horizontal padding/inset of a Button seems to change depending on the length of its text label. Here is a minimal example: VStack { Button { } label: { Text("我是一段很长的文字") .lineLimit(nil) .frame(maxWidth: .infinity, alignment: .leading) .border(.red) } Button { } label: { Text("我是一段") .lineLimit(nil) .frame(maxWidth: .infinity, alignment: .leading) .border(.red) } } .frame(width: 100) .border(.red) In Preview, the outer VStack has a fixed width of 100pt, and both Button labels use: .frame(maxWidth: .infinity, alignment: .leading) The red border around each Text shows that the label itself is receiving the expected available width. However, the two Buttons appear to have different horizontal insets between the Button's edge and the Text's edge, even though both Buttons are inside the same VStack and have the same layout configuration. In other words, the Button's apparent internal padding seems to depend on the intrinsic width / length of the label: ┌────────────────────┐ │ ┌──────────────┐ │ │ │ Long text │ │ │ └──────────────┘ │ └────────────────────┘ ┌────────────────────┐ │ ┌────────────┐ │ │ │ Short text │ │ │ └────────────┘ │ └────────────────────┘ What I find particularly confusing is that the label itself has: .frame(maxWidth: .infinity) so I would expect both Button labels to occupy the same available width. I'm trying to understand whether this is expected behavior of the default Button style or a consequence of SwiftUI's layout proposal/intrinsic-size system. Specifically: Why does the Button's apparent horizontal padding change based on the label's text length? Does the default Button style intentionally use the label's intrinsic/ideal size when determining its content inset? Is there an official SwiftUI API to specify a fixed horizontal content inset/padding for a Button, independent of the label's intrinsic size? If I want both Buttons to have exactly the same internal horizontal padding, what is the recommended SwiftUI approach? Is there a way to make the Button give its label the full proposed width before applying its own default styling/insets? I'm aware that I can implement a custom ButtonStyle, but I'm specifically wondering whether there is an existing SwiftUI API or modifier intended for controlling this behavior while retaining the system Button style. I'm seeing this behavior in recent versions of SwiftUI and would appreciate any clarification on the intended layout behavior and the recommended solution. Thanks!
Replies
0
Boosts
0
Views
248
Activity
1w
Xcode MCP: Is Swift Package dependency management supported?
Hi Apple, I’m exploring the built-in MCP support in Xcode 27 and noticed that the available Xcode MCP tools don’t seem to provide a way for an agent to manage Swift Package dependencies. For example, an agent can inspect and modify source code, build the project, run tests, and diagnose build issues. However, I haven’t found an MCP tool that allows the agent to perform operations such as: Add a Swift Package dependency to an Xcode project Remove a Swift Package dependency Add/remove a package product from a target Change the version/branch/revision requirement of a package dependency For example, I’d like to be able to give an agent an instruction such as: Add https://github.com/xxx/SomePackage.git to the project, use version 1.2.0 or later, and link the SomePackage product to the MyApp target. At the moment, it appears that the agent can identify that the package is missing when compilation fails, but it cannot actually perform the package configuration step through the Xcode MCP tools. Is Swift Package dependency management intentionally not exposed through Xcode MCP at this time? If it is not currently supported, are there plans to expose APIs/tools for managing: Package dependencies Package products Target-package relationships Package version requirements This would be particularly useful for coding agents, since adding a dependency is a common part of an otherwise automated development workflow. I've submitted a request to feedback, the id is FB24676163. Thanks!
Replies
0
Boosts
0
Views
98
Activity
1w
How can I prevent Siri Remote Back button from dismissing a fullScreenCover on tvOS?
I'm developing a tvOS application using SwiftUI, and I have a custom video player presented using fullScreenCover. .fullScreenCover(isPresented: $isPlayerPresented) { PlayerView() } I would like to implement the same kind of behavior commonly seen in video players: The player is presented full screen. When the playback controls are visible, pressing the Siri Remote Back button should hide the controls. The player should remain presented. Only when the controls are already hidden should pressing Back dismiss the player. However, I am unable to intercept the Back button before the fullScreenCover is dismissed. I have tried several approaches, including: .onExitCommand { // Handle Back } and handling UIPress / .menu events through UIKit. The problem is that when the Siri Remote Back button is pressed while the view is presented using fullScreenCover, the fullScreenCover is dismissed directly. My custom view does not appear to be able to prevent the dismissal. I also tried placing a custom UIView / UITapGestureRecognizer inside the fullScreenCover to intercept the remote button event, but the presentation is still dismissed. According to the SwiftUI documentation, onExitCommand responds to the tvOS exit command generated by the Menu button, but it does not appear to provide a way to prevent the system from dismissing a fullScreenCover in response to the Siri Remote Back button. I also noticed that interactiveDismissDisabled(_:) does not appear to provide a solution for this particular tvOS behavior. My questions Is the Siri Remote Back button expected to automatically dismiss a SwiftUI fullScreenCover on tvOS? Is there a supported API to intercept the Back button before the fullScreenCover is dismissed? Is there a way to tell SwiftUI that a fullScreenCover should not be dismissed by the Siri Remote Back button? If fullScreenCover is not intended for this use case, what is the recommended way to implement a custom full-screen video player that needs to control Back-button behavior? The desired behavior is essentially: Back button ↓ Are playback controls visible? ├── Yes → hide controls, keep player presented └── No → dismiss player I would appreciate any guidance on the intended tvOS API or recommended architecture for implementing this behavior. Thanks!
Replies
1
Boosts
0
Views
694
Activity
1w
Xcode Cloud Build Failed with Preparing build for App Store Connect failed
My project build failed in Xcode Cloud(works well in my local Mac), and the error shows: Preparing build for App Store Connect failed The error message is not clear enough to help us find the solution to fix it. Can anyone help with it?
Replies
8
Boosts
1
Views
1.8k
Activity
Jan ’26
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
Replies
1
Boosts
0
Views
207
Activity
Jan ’26
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") } } } }
Replies
1
Boosts
0
Views
227
Activity
Dec ’25
Concurrency warning in Translation API
I encountered a concurrency compilation warning when calling the TranslationSession.translations(from: [TranslationSession.Request]) API, and I'm don't know how to resolve it. I reviewed the official demo, but it appears identical.
Replies
1
Boosts
0
Views
479
Activity
Dec ’25
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?
Replies
2
Boosts
0
Views
898
Activity
Nov ’25
Mergeable library is not compatible with SwiftUI preview
When I enable the Mergeable library in Xcode, SwiftUI preview will be not available, and the error is as follows. Cannot preview in this file Could not analyze the built target description for Demo to create the preview. arguments: -no_merge_framework: Failed parsing Mach-O file Assets Report
Replies
2
Boosts
0
Views
500
Activity
Sep ’25
Debug Failed in Xcode Simulator
I can‘t use breakpoints on the simulator after updating Xcode and the simulator. I can use breakpoints on a physical iPhone. I tired to download other iOS simulator version, but still not working. Both SwiftUI and UIKit not working. Xcode version: 16.2 SDK version: 18.2 (22C146) Simulator version: 18.3.1 (22D8075) Mac OS version: 15.4 Beta Couldn't find the Objective-C runtime library in loaded images. Message from debugger: The LLDB RPC server has crashed. You may need to manually terminate your process. The crash log is located in ~/Library/Logs/DiagnosticReports and has a prefix 'lldb-rpc-server'. Please file a bug and attach the most recent crash log.
Replies
49
Boosts
63
Views
17k
Activity
Apr ’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 })) } }
Replies
2
Boosts
0
Views
153
Activity
Mar ’25
"SwiftGenPlugin" is disabled in Xcode Cloud
My project uses a local swift package of my own, which uses SwiftGenPlugin to generate image resources. I can archive the project locally, but Xcode Cloud doesn't work and reports an error: "SwiftGenPlugin" is disabled.
Replies
0
Boosts
0
Views
340
Activity
Feb ’25
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.
Replies
2
Boosts
0
Views
1k
Activity
Jun ’24
listRowSpacing support section
listRowSpacing only support the whole List, but sometimes we want to apply different spacing for different section in List.
Replies
1
Boosts
0
Views
718
Activity
Jun ’24
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?
Replies
0
Boosts
0
Views
509
Activity
Dec ’23