### Setup UIOnboarding Helper Components Source: https://github.com/lascic/uionboarding/blob/main/README.md Provides helper functions to configure various components of the UIOnboarding view, including app icon, title lines, features, notice text, and button configuration. ```swift import UIKit import UIOnboarding struct UIOnboardingHelper { // App Icon static func setUpIcon() -> UIImage { return Bundle.main.appIcon ?? .init(named: "onboarding-icon")! } // First Title Line // Welcome Text static func setUpFirstTitleLine() -> NSMutableAttributedString { .init(string: "Welcome to", attributes: [.foregroundColor: UIColor.label]) } // Second Title Line // App Name static func setUpSecondTitleLine() -> NSMutableAttributedString { .init(string: Bundle.main.displayName ?? "Insignia", attributes: [ .foregroundColor: UIColor.init(named: "camou")! ]) } // Core Features static func setUpFeatures() -> Array { return .init([ .init(icon: .init(named: "feature-1")!, title: "Search until found", description: "Over a hundred insignia of the Swiss Armed Forces – each redesigned from the ground up."), .init(icon: .init(named: "feature-2")!, title: "Enlist prepared", description: "Practice with the app and pass the rank test on the first run."), .init(icon: .init(named: "feature-3")!, title: "#teamarmee", description: "Add name tags of your comrades or cadre. Insignia automatically keeps every name tag you create in iCloud.") ]) } // Notice Text static func setUpNotice() -> UIOnboardingTextViewConfiguration { return .init(icon: .init(named: "onboarding-notice-icon")!, text: "Developed and designed for members of the Swiss Armed Forces.", linkTitle: "Learn more...", link: "https://www.lukmanascic.ch/portfolio/insignia", linkColor: .init(named: "camou")) } // Continuation Title static func setUpButton() -> UIOnboardingButtonConfiguration { return .init(title: "Continue", titleColor: .white, // Optional, `.white` by default backgroundColor: .init(named: "camou")!) } } ``` -------------------------------- ### Add UIOnboarding Package Source: https://github.com/lascic/uionboarding/blob/main/README.md Use Swift Package Manager to add the UIOnboarding library to your Xcode project. Specify the version or branch for installation. ```swift .package(url: "https://github.com/lascic/UIOnboarding.git", from: "2.0.0") ``` ```swift .package(url: "https://github.com/lascic/UIOnboarding.git", branch: "main") ``` -------------------------------- ### Set Up UIOnboardingViewConfiguration Source: https://github.com/lascic/uionboarding/blob/main/README.md Creates a complete UIOnboardingViewConfiguration object using the helper functions. This configuration is used to initialize the onboarding view controller. ```swift import UIOnboarding extension UIOnboardingViewConfiguration { // UIOnboardingViewController init static func setUp() -> UIOnboardingViewConfiguration { return .init(appIcon: UIOnboardingHelper.setUpIcon(), firstTitleLine: UIOnboardingHelper.setUpFirstTitleLine(), secondTitleLine: UIOnboardingHelper.setUpSecondTitleLine(), features: UIOnboardingHelper.setUpFeatures(), textViewConfiguration: UIOnboardingHelper.setUpNotice(), buttonConfiguration: UIOnboardingHelper.setUpButton()) } } ``` -------------------------------- ### Configure Localized Welcome Title Source: https://github.com/lascic/uionboarding/blob/main/README.md Demonstrates how to set up a single-line welcome title by providing an empty attributed string for the second title line. The UIOnboardingTitleLabelStack adjusts automatically. ```swift // First Title Line // App Name static func setUpFirstTitleLine() -> NSMutableAttributedString { return .init(string: Bundle.main.displayName ?? "Distintivos", attributes: [ .foregroundColor: UIColor.init(named: "camou")! ]) } // Second Title Line // Empty static func setUpSecondTitleLine() -> NSMutableAttributedString { return .init(string: "") } ``` -------------------------------- ### SwiftUI OnboardingView Implementation Source: https://github.com/lascic/uionboarding/blob/main/README.md Implement the UIViewControllerRepresentable protocol to create a SwiftUI view for UIOnboardingViewController. Assign the coordinator as the delegate. ```swift // In OnboardingView.swift import SwiftUI import UIOnboarding struct OnboardingView: UIViewControllerRepresentable { typealias UIViewControllerType = UIOnboardingViewController func makeUIViewController(context: Context) -> UIOnboardingViewController { let onboardingController: UIOnboardingViewController = .init(withConfiguration: .setUp()) onboardingController.delegate = context.coordinator return onboardingController } func updateUIViewController(_ uiViewController: UIOnboardingViewController, context: Context) {} class Coordinator: NSObject, UIOnboardingViewControllerDelegate { func didFinishOnboarding(onboardingViewController: UIOnboardingViewController) { onboardingViewController.dismiss(animated: true, completion: nil) } } func makeCoordinator() -> Coordinator { return .init() } } ``` -------------------------------- ### Conditionally Show Onboarding Source: https://github.com/lascic/uionboarding/blob/main/README.md Checks a UserDefaults flag to determine if the onboarding has been completed. If not, it calls a function to display the onboarding screen. ```swift if !UserDefaults.standard.bool(forKey: "hasCompletedOnboarding") { showOnboarding() } ``` -------------------------------- ### Handle Onboarding Completion Source: https://github.com/lascic/uionboarding/blob/main/README.md Dismisses the onboarding view controller with a cross-dissolve transition and sets a UserDefaults flag to indicate that onboarding is complete. ```swift func didFinishOnboarding(onboardingViewController: OnboardingViewController) { onboardingViewController.modalTransitionStyle = .crossDissolve onboardingViewController.dismiss(animated: true) { UserDefaults.standard.set(true, forKey: "hasCompletedOnboarding") } } ``` -------------------------------- ### SwiftUI ContentView with Onboarding Trigger Source: https://github.com/lascic/uionboarding/blob/main/README.md A SwiftUI ContentView that uses a button to trigger the presentation of the OnboardingView via a .fullScreenCover modifier. ```swift // In ContentView.swift import SwiftUI struct ContentView: View { @State private var showingOnboarding = true var body: some View { NavigationView { Text("Hello, UIOnboarding!") .toolbar { Button { showingOnboarding = true } label: { Image(systemName: "repeat") } } .fullScreenCover(isPresented: $showingOnboarding, content: { OnboardingView.init() .edgesIgnoringSafeArea(.all) }) } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView.init() } } ``` -------------------------------- ### Present UIOnboarding in UIKit Source: https://github.com/lascic/uionboarding/blob/main/README.md Present the UIOnboardingViewController from a UIKit view controller. Ensure the presenting view controller is embedded in a UINavigationController. ```swift import UIKit import UIOnboarding let onboardingController: UIOnboardingViewController = .init(withConfiguration: .setUp()) onboardingController.delegate = self navigationController?.present(onboardingController, animated: false) ``` -------------------------------- ### Present UIOnboarding in SwiftUI Source: https://github.com/lascic/uionboarding/blob/main/README.md Use the .fullScreenCover modifier to present the OnboardingView in a SwiftUI application. This requires wrapping the UIOnboardingViewController using UIViewControllerRepresentable. ```swift .fullScreenCover(isPresented: $showingOnboarding, content: { OnboardingView.init() .edgesIgnoringSafeArea(.all) } ``` -------------------------------- ### Dismiss UIOnboarding in UIKit Source: https://github.com/lascic/uionboarding/blob/main/README.md Implement the UIOnboardingViewControllerDelegate method to dismiss the onboarding view controller. This is typically called when the user completes the onboarding process. ```swift extension ViewController: UIOnboardingViewControllerDelegate { func didFinishOnboarding(onboardingViewController: UIOnboardingViewController) { onboardingViewController.modalTransitionStyle = .crossDissolve onboardingViewController.dismiss(animated: true, completion: nil) } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.