Post

Replies

Boosts

Views

Activity

Reply to Alerts and Action Sheets not using SwiftUI accent color
It looks like the issue is with UIColor.tintColor. A color value that resolves at runtime based on the current tint color of the app or trait hierarchy. When adding this line of code: UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = .tintColor the same buggy behaviour occurs, but setting it to any other colour makes it work fine. Apple's implementation must use UIColor.tintColor which is why alert buttons' colours are "broken".
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’22
Reply to SwiftUI Three Toggles that dissable eachother
Something like this will work: @State private var selectedToggle = 1 var body: some View { VStack { ForEach(1...3, id: \.self) { num in Toggle("Toggle \(num)", isOn: toggleBinding(for: num)) } } } func toggleBinding(for num: Int) -> Binding<Bool> { Binding { num == selectedToggle } set: { _ in selectedToggle = num } } You can adjust this to suit your needs.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’22
Reply to How to pass a Swift Type into an Generic SwiftUI View?
Could you not pass in the actual value to GenericView and remove the generics. Something like this: struct GenericView: View {     var component: any Component     var body: some View {         Text(component.name)     } } struct MainView: View {     var body: some View {         GenericView(component: componentType)     }     private var component: any Component {         // This returns a value that conforms to Component     } } Or would this not be possible because it removes the generics, or you just want the type being passed around instead of the actual value? I don't know if any and generics work the best together. You could think of using some instead of any, but it's whatever suits your needs.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’22
Reply to Use iPhone's Proximity Sensor
You can retrieve the proximityState value from the current UIDevice and detect when it changes. You need to enable proximity monitoring first and I suggest doing that in your main App struct. // in main App struct init() {     UIDevice.current.isProximityMonitoringEnabled = true } struct ContentView: View {     @State private var theNumber = 0     var body: some View {         Text("\(theNumber)")             .onReceive(NotificationCenter.default.publisher(for: UIDevice.proximityStateDidChangeNotification)) { _ in                 if UIDevice.current.proximityState { // sensor is close to user // true is "near", false is "far"                     theNumber += 1                 }             }     } } ‎ Things to Note The sensor detects objects up to 10 cm away. When the sensor detects an object that is close, the screen turns off. There is no single point where the proximity state switches between "near" and "far", but instead a buffer range. When the state is "far", the object must be up to 5 cm from the sensor in order to change the state to "near". When the state is "near", the object must be at least 10 cm from the sensor in order to change the state to "far".
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’22
Reply to SwiftUI Mac navigation title is not editable
It works correctly on iOS and iPadOS 16 and that's maybe what the documentation is referring to. In the Renaming section of this article, it explains this feature is available on macOS but the indicator is for iOS. I haven't seen editable navigation titles yet in macOS Ventura, so I don't know what they would look like.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’22
Reply to How to show SwiftUI PhotosPicker programatically
There is already a modifier for this. It has the same parameters as the PhotosPicker view and comes in its different variants. photosPicker(isPresented:selection:maxSelectionCount:selectionBehavior:matching:preferredItemEncoding:photoLibrary:) -> some View I couldn't find it in the documentation, but you can find it in Xcode's generated interface for SwiftUI.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’22