Post

Replies

Boosts

Views

Activity

Reply to ToolbarItem placement problem: Button text is not centered
Thanks for the quick feedback. In your image, the text is not entirely centered but right aligned. To clarify myself, I removed the button corner radius and add the same button to the screen center. You can see in my attached screenshot the default text alignment is different between the two buttons. The button text in the toolbar is obviously right aligned (The last "m" is closer to the edge than the beginning "c"). I have tried a few different ToolBarItem placements. Placements like .confirmationAction or .navigationBarTrailing, etc. all have this behaviour. In my opinion, it should be the button not the text that gets right aligned. If this is not a bug, what is the solution to this? import SwiftUI struct TestView: View {   var body: some View {     NavigationView {       ZStack {         Color(.black)           .ignoresSafeArea()         Text("Hello World")           .foregroundColor(.white)           .toolbarRole(.editor)           .toolbar {             ToolbarItem(placement: .confirmationAction) {               Button(action: {print("confirm.")}) {                 Text("confirm")               }               .background(.yellow)               .foregroundColor(.white)             }           }         Button(action: {print("confirm.")}) {           Text("confirm")         }         .background(.yellow)         .foregroundColor(.white)         .offset(y: 20)       }     }   } } struct TestView_Previews: PreviewProvider {   static var previews: some View {     TestView()   } }
Jun ’22
Reply to ToolbarItem placement problem: Button text is not centered
Following is a workaround which forces the center alignment to the text in the button of toolbar. However, I still need to know if this is a bug. Button(action: {print("confirm.")}) {                 Text("confirm")                   .alignmentGuide(HorizontalAlignment.center, computeValue: { d in                     d[HorizontalAlignment.center]                   })               }
Jun ’22
Reply to Scroll Position does not work with dynamic content
The answer to this is in the documentation: When configuring a scroll position, SwiftUI will attempt to keep that position stable. For an edge, that means keeping a top aligned scroll view scrolled to the top if the content size changes. For a point, SwiftUI won’t attempt to keep that exact offset scrolled when the content size changes nor will it update to a new offset when that changes.
Aug ’24
Reply to Preview crashes consistency in Xcode 16 beta
In Xcode 16.1 beta, live preview fails in large (scheme) project, even for the simplest view such as hello world text. It takes very long time to build the view and eventually report over 15 seconds time limit. I am pretty the such a simple view doesn't have reference to any other project files. However, if I copy the view into a fresh created project, the live preview works. This situation also applies to the live preview on device.
Aug ’24