Post

Replies

Boosts

Views

Activity

Reply to NavigationSplitView with Custom Views as Labels
I'm not really sure what you're asking. If you want to know how to show a different view based on the current selection then you can see the ammended code below: @State var selectedNavigationCategory: NavigationCategory? let navigationCategories = [     NavigationCategory(id: UUID(), name: "One", sfSymbol: "circle"),     NavigationCategory(id: UUID(), name: "Two", sfSymbol: "circle.fill") ] var body: some View {     NavigationSplitView {         List(navigationCategories, selection: $selectedNavigationCategory) { category in             NavigationLink(value: category) {                 Label(category.name, systemImage: category.sfSymbol)             }         }     } detail: {         ZStack { // workaround in beta 2             if let selectedNavigationCategory {                 // Something has been selected // Show the corresponding view for this                 Text("You selected \(selectedNavigationCategory.name)")             } else {                 // Nothing is selected // Placeholder text                 Text("Select something")             }         }     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’22
Reply to Unable to change Toggles
Move the @State property wrapper from the selected variable in the mySession struct to the sessions array. You can then pass a binding directly into the Toggle, like this: ForEach($sessions) { $session in Toggle(isOn: $session.selected) { Text(session.name) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to I have problem with this code. I try to append it but i get some error so please help
The variable Produkt is of type Array<ScannProdukt>. In the addRow method, you are appending the value stored in ScannedCode to this array which is of type String. The error comes from the fact that the array expects a value of type ScannProdukt to be appended, but instead got a value of type String. You would need to use the ScannedCode property to create a ScannProdukt that can be appended to the Produkt array.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Safe Area Insets
I'm assuming you're using SwiftUI since that's what you tagged the question with. If so, your views should automatically be placed to fit in the safe area. Using the ignoresSafeArea(_:edges:) modifier, well, ignores the safe area, so expanding to fill the whole screen. If you want your views to fill the entire space inside of the safe area, you can use a frame modifier like this: .frame(maxWidth: .infinity, maxHeight: .infinity) If you explicitly want the top and bottom safe area inset values, then you can wrap your view in a GeometryReader and access the values like this: GeometryReader { geoProxy in let topInset = geoProxy.safeAreaInsets.top let bottomInset = geoProxy.safeAreaInsets.bottom ... }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to SwiftUI 4: Set list background color
New in iOS 16 beta 3, two new modifiers! You can use them to set a background colour for a list: List { ... } .scrollContentBackground(Color.red) // using .red results in an error or set a custom background view: List { ... } .scrollContentBackground(.hidden) .background {     Image(systemName: "list.bullet")         .resizable()         .scaledToFit()         .padding() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Can't change List background color in iOS 16
New in iOS 16 beta 3, two new modifiers! You can use them to set a background colour for a list: List { ... } .scrollContentBackground(Color.red) // using .red results in an error or set a custom background view: List { ... } .scrollContentBackground(.hidden) .background {     Image(systemName: "list.bullet")         .resizable()         .scaledToFit()         .padding() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Load link from tab bar item
You can detect when the user taps on the specified tab with this: // add to the TabView .onChange(of: selectedTab) { [selectedTab] newTab in if newTab == "OpenLinkTab" { self.selectedTab = selectedTab // return to previously selected tab // open URL here         let url = URL(string: "https://www.apple.com")! openURL(url) } } When the tab item is tapped, it will look like a regular button press as the tab view switches back to the previously selected tab. This is when you can open the link providing the behaviour you want. This solution would be similar to implementing the UITabBarControllerDelegate.tabBarController(_:shouldSelect:) delegate method and returning false (in a UIKit app).
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to navigationTitle with menu
In beta 1, navigationTitle(_:actions:) was how you would set the menu's actions. In beta 2, a new modifier was added for this instead. It was called toolbarTitleActions(actions:). As of beta 3, you will have to use the renamed toolbarTitleMenu(content:) modifier, like this: .toolbarTitleMenu { MyPrintButton() } Note: the menu will only show when the navigation title display mode is .inline.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to SwiftUI slowly adoption
What they actually said during the talk was this: ... if you're new to our platforms or if you're starting a brand-new app, the best way to build an app is with Swift and SwiftUI. Features can be added to existing apps, and Apple is trying to slowly incorporate SwiftUI into UIKit (and other platform-equivalent frameworks), but the orignial statement is aimed at people starting with Swift and learning to build apps with SwiftUI. Companies with apps can still use UIKit (and similar) and incrementally adopt SwiftUI, but don't have to restructure everything, yet.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Handling a single window app on MacOS with Swift
The first point can easily be solved through the use of a custom class conforming to the NSApplicationDelegate, implemented like this: class AppDelegate: NSObject, NSApplicationDelegate {     func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {         return true     } } and then adding this to the main app file: @NSApplicationDelegateAdaptor private var appDelegate: AppDelegate On your second point, if needed, you can use the new in Ventura Window struct as the main scene of your app, like this: @main struct SingleWindowApp: App { var body: some Scene { Window("SingleWindow", id: "main") { ContentView() } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Back supported Navigation-View
NavigationView has only been soft deprecated, so will still function on iOS 16. As for manually back deploying, since NavigationView has been split into two parts but come with added components, such as a path and control over column visibility as well as the new NavigationLink(_:value:) and navigationDestination modifier, it would be quite difficult to accomodate all of this.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to ForEach loop or initializer broken
I have managed to narrow down the issue to the while loop. If it were replaced by a for loop, like this: for _ in 1...20 { numm.append(.random(in: 0...1)) fill += 1 } it would compile and the preview would work. Note: the fill variable is now redundant and won't do anything, unless you use it later on somewhere. After some more debugging, I found that everything in the initialiser has no effect on the two @State variables. You have given them initial values and then tried to change them immediately. Instead, declare them with no value and then set them in the initialiser, like this: @State private var numm: [Int] @State private var fill: Int init() {     _fill = State(initialValue: 0)     var initialNumm: [Int] = []     for _ in 1...20 {         initialNumm.append(.random(in: 0...1))     }     _numm = State(initialValue: initialNumm) } Everything else can be kept the same the way you wrote it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22
Reply to Handling single selection action in multi-selection SwiftUI Table
I recently came across a new modifier in macOS Ventura called contextAction(forSelectionType:action:) and seems to do what you are describing. The closure that is run can be used to perform the navigation or whatever you need to happen. I'm currently on Monterey so I don't know how well it works on macOS, but I did try it out on iOS 16. Multi-selection still works when in edit mode, but when edit mode is inactive, tapping on a row performs the closure. Hopefully this helps, and when you try it out on Ventura it works.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’22