Post

Replies

Boosts

Views

Activity

Reply to Callback from onTapGesture Through Framework
I've removed the optional part in the framework as follows. And it works. I don't know why the callBack guy can't be optional, though, in the framework. import SwiftUI public struct ColorSelectorView: View { @Binding var selectedColor: Color @State var callBack: ((Color) -> Void) let colors: [Color] = [.blue, .green, .orange, .yellow, .red, .purple] public init(selectedColor: Binding<Color>, callBack: @escaping ((Color) -> Void)) { self._selectedColor = selectedColor self.callBack = callBack } public var body: some View { HStack { ForEach(colors, id: \.self) { color in Image(systemName: selectedColor == color ? "record.circle.fill" : "circle.fill") .foregroundColor(color) .onTapGesture { selectedColor = color callBack(color) } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’23
Reply to Switching Locale with Picker
I've made some change the App View as follows. import SwiftUI @main struct LocaleSwitchCrazyMamaApp: App { @StateObject var lanSetting = LanguageSetting() var body: some Scene { WindowGroup { ContentView() .environmentObject(lanSetting) .environment(\.locale, lanSetting.locale) } } } The outcome doesn't change, though.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to Strange Overlay with NSWorkspace.shared.icon(forFile: )
Personally, I think it's a SwiftUI bug. I have a similar problem with the ImageRenderer class and get the same symbol. I've filed a feedback report. It's been 5 or 6 weeks. When I filed a bug report 9 or 10 years ago regarding Core Graphics, I had to wait for 3 months. If possible, you may write code in Cocoa and use it as NSViewControllerRepresentable or NSViewRepresentable.
Topic: UI Frameworks SubTopic: AppKit Tags:
Oct ’23
Reply to SwiftUI tabItem Label Text Cut Off on iPad
You can simply use HStack to separate the name text and its corresponding image. import SwiftUI struct ContentView: View { var body: some View { TabView{ FirstView() .tabItem { HStack { Text("Save") .fixedSize() Image(systemName: "lock.fill") } } SecondView() .tabItem { HStack { Text("Things") .fixedSize() Image(systemName: "message.fill") } } } } } struct FirstView: View { var body: some View { Text("First") } } struct SecondView: View { var body: some View { Text("Second") } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’23