### Customize UISwitch from SwiftUI Toggle Source: https://context7.com/context7/swiftpackageindex_siteline_swiftui-introspect_26_0_0/llms.txt This example demonstrates how to customize a UISwitch used in a SwiftUI Toggle. It enables modification of colors and the addition of haptic feedback upon value changes. The SwiftUIIntrospect library is required for this functionality. ```swift import SwiftUI import SwiftUIIntrospect struct ToggleExample: View { @State private var isEnabled = false @State private var notifications = true var body: some View { Form { Toggle("Enable Feature", isOn: $isEnabled) .introspect(.toggle, on: .iOS(.v15, .v16, .v17)) { uiSwitch in // Customize colors uiSwitch.onTintColor = .systemGreen uiSwitch.thumbTintColor = .white // Add haptic feedback uiSwitch.addTarget( uiSwitch, action: #selector(uiSwitch.triggerHaptic), for: .valueChanged ) } Toggle("Notifications", isOn: $notifications) .introspect(.toggle, on: .iOS(.v15, .v16, .v17)) { uiSwitch in uiSwitch.onTintColor = .systemOrange } } } } extension UISwitch { @objc func triggerHaptic() { let generator = UIImpactFeedbackGenerator(style: .light) generator.impactOccurred() } } ``` -------------------------------- ### Introspect UIScrollView in SwiftUI Source: https://context7.com/context7/swiftpackageindex_siteline_swiftui-introspect_26_0_0/llms.txt This example demonstrates how to access and customize a UIScrollView from a SwiftUI ScrollView. It enables control over scrolling behavior such as bounciness and scroll indicator visibility, and allows for the addition of native components like a refresh control. ```swift import SwiftUI import SwiftUIIntrospect struct ScrollViewExample: View { var body: some View { ScrollView { VStack(spacing: 20) { ForEach(0..<50) { index in Text("Row \(index)") .frame(maxWidth: .infinity) .padding() .background(Color.gray.opacity(0.2)) } } .padding() } .introspect(.scrollView, on: .iOS(.v15, .v16, .v17)) { scrollView in // Customize scroll behavior scrollView.bounces = true scrollView.showsVerticalScrollIndicator = false scrollView.decelerationRate = .fast // Add refresh control let refreshControl = UIRefreshControl() refreshControl.addTarget( scrollView, action: #selector(scrollView.refreshTriggered), for: .valueChanged ) scrollView.refreshControl = refreshControl } } } ``` -------------------------------- ### Customize UITableView from SwiftUI List Source: https://context7.com/context7/swiftpackageindex_siteline_swiftui-introspect_26_0_0/llms.txt Access and modify UITableView properties for advanced customization of SwiftUI Lists. This example shows how to change background color, separator style, and row height, and enable cell reordering. It requires the SwiftUIIntrospect library and targets iOS versions 15, 16, and 17. ```swift import SwiftUI import SwiftUIIntrospect struct ListExample: View { @State private var items = Array(1...100) var body: some View { List { ForEach(items, id: \.self) { item in HStack { Image(systemName: "star.fill") .foregroundColor(.yellow) Text("Item \(item)") } } .onDelete(perform: deleteItems) } .introspect(.list, on: .iOS(.v15, .v16, .v17)) { tableView in // Customize table view appearance tableView.backgroundColor = .systemGroupedBackground tableView.separatorStyle = .singleLine tableView.separatorInset = UIEdgeInsets(top: 0, left: 50, bottom: 0, right: 0) // Performance optimizations tableView.rowHeight = UITableView.automaticDimension tableView.estimatedRowHeight = 44 // Enable cell reordering tableView.isEditing = false tableView.allowsMultipleSelectionDuringEditing = true } } func deleteItems(at offsets: IndexSet) { items.remove(atOffsets: offsets) } } ``` -------------------------------- ### Customize UITabBarController from SwiftUI TabView Source: https://context7.com/context7/swiftpackageindex_siteline_swiftui-introspect_26_0_0/llms.txt Customize tab bar appearance and behavior beyond SwiftUI's TabView API. This example demonstrates changing the tab bar's background color, tab item colors, and adding haptic feedback on selection. It uses the SwiftUIIntrospect library and is compatible with iOS versions 15, 16, and 17. ```swift import SwiftUI import SwiftUIIntrospect struct TabViewExample: View { @State private var selectedTab = 0 var body: some View { TabView(selection: $selectedTab) { HomeView() .tabItem { Label("Home", systemImage: "house.fill") } .tag(0) SearchView() .tabItem { Label("Search", systemImage: "magnifyingglass") } .tag(1) ProfileView() .tabItem { Label("Profile", systemImage: "person.fill") } .tag(2) } .introspect(.tabView, on: .iOS(.v15, .v16, .v17)) { tabBarController in // Customize tab bar appearance let appearance = UITabBarAppearance() appearance.configureWithOpaqueBackground() appearance.backgroundColor = .systemBackground // Customize tab item colors appearance.stackedLayoutAppearance.selected.iconColor = .systemBlue appearance.stackedLayoutAppearance.selected.titleTextAttributes = [ .foregroundColor: UIColor.systemBlue ] appearance.stackedLayoutAppearance.normal.iconColor = .systemGray appearance.stackedLayoutAppearance.normal.titleTextAttributes = [ .foregroundColor: UIColor.systemGray ] tabBarController.tabBar.standardAppearance = appearance tabBarController.tabBar.scrollEdgeAppearance = appearance // Add haptic feedback on tab selection tabBarController.tabBar.tintColor = .systemBlue } } } struct HomeView: View { var body: some View { NavigationView { Text("Home Content") .navigationTitle("Home") } } } struct SearchView: View { var body: some View { NavigationView { Text("Search Content") .navigationTitle("Search") } } } struct ProfileView: View { var body: some View { NavigationView { Text("Profile Content") .navigationTitle("Profile") } } } ``` -------------------------------- ### Customize UIViewController with SwiftUI Introspect Source: https://context7.com/context7/swiftpackageindex_siteline_swiftui-introspect_26_0_0/llms.txt Access and customize UIViewController for view lifecycle hooks and presentation methods using SwiftUI Introspect. This allows for observing lifecycle events like viewDidAppear, customizing presentation styles, and managing UI element visibility. It requires the SwiftUIIntrospect library. ```swift import SwiftUI import SwiftUIIntrospect struct ViewControllerExample: View { @State private var isPresented = false @State private var viewDidAppearCount = 0 var body: some View { VStack(spacing: 20) { Text("Appeared \(viewDidAppearCount) times") .font(.headline) Button("Show Sheet") { isPresented = true } } .introspect(.viewController, on: .iOS(.v15, .v16, .v17)) { viewController in // Observe lifecycle events let notificationCenter = NotificationCenter.default notificationCenter.addObserver( forName: UIViewController.viewDidAppearNotification, object: viewController, queue: .main ) { _ in viewDidAppearCount += 1 } // Customize presentation viewController.modalPresentationStyle = .automatic viewController.modalTransitionStyle = .coverVertical // Force dark/light mode viewController.overrideUserInterfaceStyle = .unspecified // Hide home indicator viewController.setNeedsUpdateOfHomeIndicatorAutoHidden() } .sheet(isPresented: $isPresented) { SheetContent() } } } struct SheetContent: View { @Environment(\.dismiss) var dismiss var body: some View { NavigationView { Text("Sheet Content") .navigationTitle("Details") .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button("Done") { dismiss() } } } } .introspect(.viewController, on: .iOS(.v15, .v16, .v17)) { viewController in // Customize sheet presentation if let presentationController = viewController.presentationController as? UISheetPresentationController { presentationController.detents = [.medium(), .large()] presentationController.prefersGrabberVisible = true presentationController.preferredCornerRadius = 20 } } } } extension UIViewController { static let viewDidAppearNotification = Notification.Name("ViewControllerDidAppear") } ``` -------------------------------- ### Cross-Platform List Introspection in SwiftUI Source: https://context7.com/context7/swiftpackageindex_siteline_swiftui-introspect_26_0_0/llms.txt Shows how to introspect and customize a SwiftUI List for both iOS and macOS using SwiftUIIntrospect. It applies distinct styling and behavior to the underlying UITableView (iOS) and NSTableView (macOS) based on the target operating system and version. ```swift import SwiftUI import SwiftUIIntrospect struct MultiPlatformListExample: View { let items = Array(1...50) var body: some View { List(items, id: \.self) { item in Text("Item \(item)") } #if os(iOS) .introspect(.list, on: .iOS(.v15, .v16, .v17)) { tableView in tableView.separatorStyle = .none tableView.backgroundColor = .systemBackground } #elseif os(macOS) .introspect(.list, on: .macOS(.v12, .v13, .v14)) { tableView in tableView.style = .inset tableView.backgroundColor = .clear tableView.usesAlternatingRowBackgroundColors = true } #endif } } ``` -------------------------------- ### Customize UIDatePicker from SwiftUI DatePicker Source: https://context7.com/context7/swiftpackageindex_siteline_swiftui-introspect_26_0_0/llms.txt This snippet illustrates how to customize UIDatePicker instances within SwiftUI's DatePicker. It covers modifying preferred styles, tint colors, setting date constraints, and configuring locale and time zone. The SwiftUI Introspect library is necessary. ```swift import SwiftUI import SwiftUIIntrospect struct DatePickerExample: View { @State private var selectedDate = Date() @State private var birthDate = Date() var body: some View { Form { Section("Compact Style") { DatePicker("Select Date", selection: $selectedDate) .introspect(.datePicker(style: .compact), on: .iOS(.v15, .v16, .v17)) { datePicker in // Customize appearance datePicker.preferredDatePickerStyle = .compact datePicker.tintColor = .systemBlue // Set date constraints datePicker.minimumDate = Calendar.current.date(byAdding: .year, value: -100, to: Date()) datePicker.maximumDate = Date() // Configure locale datePicker.locale = Locale.current datePicker.timeZone = TimeZone.current } } Section("Wheel Style") { DatePicker("Birth Date", selection: $birthDate, displayedComponents: [.date]) .datePickerStyle(.wheel) .introspect(.datePicker(style: .wheel), on: .iOS(.v15, .v16, .v17)) { datePicker in datePicker.preferredDatePickerStyle = .wheels datePicker.maximumDate = Date() // Customize for birth date selection if let minDate = Calendar.current.date(byAdding: .year, value: -120, to: Date()) { datePicker.minimumDate = minDate } } } } } } ``` -------------------------------- ### Customize UISearchBar with SwiftUI Introspect Source: https://context7.com/context7/swiftpackageindex_siteline_swiftui-introspect_26_0_0/llms.txt Access and customize the UISearchBar from SwiftUI's searchable modifier. This allows for advanced styling and behavior configuration, such as changing the search bar style, tint color, placeholder text, and autocorrection settings. It requires the SwiftUIIntrospect library. ```swift import SwiftUI import SwiftUIIntrospect struct SearchableExample: View { @State private var searchText = "" @State private var items = [ "Apple", "Banana", "Cherry", "Date", "Elderberry", "Fig", "Grape", "Honeydew", "Kiwi", "Lemon" ] var filteredItems: [String] { if searchText.isEmpty { return items } return items.filter { $0.localizedCaseInsensitiveContains(searchText) } } var body: some View { NavigationView { List(filteredItems, id: \.self) { Text($0) } .navigationTitle("Fruits") .searchable(text: $searchText, prompt: "Search fruits") .introspect(.searchField, on: .iOS(.v15, .v16, .v17)) { searchField in // Customize search bar appearance if let searchBar = searchField.superview as? UISearchBar { searchBar.searchBarStyle = .minimal searchBar.tintColor = .systemBlue searchBar.searchTextField.backgroundColor = .systemGray6 // Configure search behavior searchBar.autocapitalizationType = .none searchBar.autocorrectionType = .no searchBar.showsCancelButton = false // Add custom placeholder attributes let attributes: [NSAttributedString.Key: Any] = [ .foregroundColor: UIColor.systemGray, .font: UIFont.systemFont(ofSize: 16) ] searchBar.searchTextField.attributedPlaceholder = NSAttributedString( string: "Search fruits", attributes: attributes ) } } } } } ``` -------------------------------- ### Introspect UINavigationController in SwiftUI Source: https://context7.com/context7/swiftpackageindex_siteline_swiftui-introspect_26_0_0/llms.txt This snippet illustrates how to access and customize the UINavigationController from a SwiftUI NavigationView. It provides methods for modifying the navigation bar's appearance, such as background color and text attributes, and for enabling/disabling gestures like the swipe back. ```swift import SwiftUI import SwiftUIIntrospect struct NavigationExample: View { var body: some View { NavigationView { List(0..<20) { index in NavigationLink("Item \(index)") { DetailView(item: index) } } .navigationTitle("Items") } .introspect(.navigationView(style: .stack), on: .iOS(.v15, .v16, .v17)) { navController in // Customize navigation bar appearance let appearance = UINavigationBarAppearance() appearance.configureWithOpaqueBackground() appearance.backgroundColor = .systemBlue appearance.titleTextAttributes = [.foregroundColor: UIColor.white] appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white] navController.navigationBar.standardAppearance = appearance navController.navigationBar.scrollEdgeAppearance = appearance navController.navigationBar.compactAppearance = appearance // Enable swipe back gesture customization navController.interactivePopGestureRecognizer?.isEnabled = true } } } struct DetailView: View { let item: Int var body: some View { Text("Detail for item \(item)") .navigationBarTitleDisplayMode(.inline) } } ``` -------------------------------- ### Cross-Platform Text Field Introspection in SwiftUI Source: https://context7.com/context7/swiftpackageindex_siteline_swiftui-introspect_26_0_0/llms.txt Demonstrates how to apply platform-specific customizations to a SwiftUI TextField using SwiftUIIntrospect. It conditionally applies different configurations for iOS and macOS, targeting specific OS versions for each platform. ```swift import SwiftUI import SwiftUIIntrospect struct CrossPlatformExample: View { @State private var text = "" var body: some View { TextField("Enter text", text: $text) #if os(iOS) .introspect(.textField, on: .iOS(.v15, .v16, .v17)) { textField in // iOS-specific UITextField customization textField.borderStyle = .roundedRect textField.clearButtonMode = .whileEditing textField.keyboardType = .default } #elseif os(macOS) .introspect(.textField, on: .macOS(.v12, .v13, .v14)) { textField in // macOS-specific NSTextField customization textField.isBordered = true textField.bezelStyle = .roundedBezel textField.focusRingType = .default } #endif } } ``` -------------------------------- ### Introspect UITextField in SwiftUI Source: https://context7.com/context7/swiftpackageindex_siteline_swiftui-introspect_26_0_0/llms.txt This snippet shows how to access and customize the underlying UITextField from a SwiftUI TextField. It allows modification of properties like border style, clear button mode, and delegate-related settings not directly available in SwiftUI's TextField API. ```swift import SwiftUI import SwiftUIIntrospect struct TextFieldExample: View { @State private var text = "" var body: some View { TextField("Enter text", text: $text) .introspect(.textField, on: .iOS(.v15, .v16, .v17)) { textField in // Customize UITextField properties textField.borderStyle = .roundedRect textField.clearButtonMode = .whileEditing textField.returnKeyType = .done textField.enablesReturnKeyAutomatically = true // Access delegate methods textField.autocapitalizationType = .words textField.autocorrectionType = .no } } } ``` -------------------------------- ### Customize UISegmentedControl from SwiftUI Picker Source: https://context7.com/context7/swiftpackageindex_siteline_swiftui-introspect_26_0_0/llms.txt This snippet shows how to access and style a UISegmentedControl embedded within a SwiftUI Picker. It allows for advanced appearance and text attribute customization using the SwiftUI Introspect library. Ensure the SwiftUIIntrospect library is imported. ```swift import SwiftUI import SwiftUIIntrospect struct PickerExample: View { @State private var selectedOption = 0 let options = ["Daily", "Weekly", "Monthly"] var body: some View { VStack(spacing: 20) { Picker("Period", selection: $selectedOption) { ForEach(0..