### Basic UITextField Example (UIKit) Source: https://developer.apple.com/design/human-interface-guidelines/text-fields This is a basic example of how to use `UITextField` in UIKit. It shows how to create and configure a text field. ```swift let textField = UITextField() textField.placeholder = "Enter text here" textField.borderStyle = .roundedRect ``` -------------------------------- ### Basic NSTextField Example (AppKit) Source: https://developer.apple.com/design/human-interface-guidelines/text-fields This is a basic example of how to use `NSTextField` in AppKit. It shows how to create and configure a text field for macOS applications. ```swift let textField = NSTextField(labelWithString: "Enter text:") textField.stringValue = "" textField.isBezeled = true textField.bezelStyle = .roundedBezel ``` -------------------------------- ### Basic Text Field with Placeholder Source: https://developer.apple.com/design/human-interface-guidelines/text-fields Demonstrates a basic text field with placeholder text to guide the user. The placeholder disappears when the user starts typing. ```swift TextField("Email", text: $email) ``` -------------------------------- ### Adjusting Layout with Keyboard Layout Guide (UIKit) Source: https://developer.apple.com/design/human-interface-guidelines/virtual-keyboards Use the keyboard layout guide to ensure your custom keyboard feels integrated and keeps important interface elements visible. This is crucial for iOS and iPadOS. ```swift import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let keyboardLayoutGuide = UILayoutGuide() view.addLayoutGuide(keyboardLayoutGuide) NSLayoutConstraint.activate([ // Constrain the keyboardLayoutGuide to the bottom of the safe area keyboardLayoutGuide.leadingAnchor.constraint(equalTo: view.leadingAnchor), keyboardLayoutGuide.trailingAnchor.constraint(equalTo: view.trailingAnchor), keyboardLayoutGuide.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor) // You would typically constrain your keyboard content to the top of this guide ]) // Example: Constraining a view to the top of the keyboard layout guide let myKeyboardView = UIView() myKeyboardView.backgroundColor = .lightGray myKeyboardView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(myKeyboardView) NSLayoutConstraint.activate([ myKeyboardView.leadingAnchor.constraint(equalTo: view.leadingAnchor), myKeyboardView.trailingAnchor.constraint(equalTo: view.trailingAnchor), myKeyboardView.bottomAnchor.constraint(equalTo: keyboardLayoutGuide.topAnchor), myKeyboardView.heightAnchor.constraint(equalToConstant: 200) ]) } } ``` -------------------------------- ### Apply Padding to Widget Content Source: https://developer.apple.com/design/human-interface-guidelines/widgets Use standard margins for widgets to ensure legibility and avoid a cluttered appearance. This example shows how to apply padding. ```swift struct MyWidgetEntryView : View { var entry: Provider.Entry var body: some View { VStack { Text(entry.date, style: .time) } .padding() ``` -------------------------------- ### Preview Scene Activation Configuration Source: https://developer.apple.com/design/human-interface-guidelines/windows Use QLPreviewSceneActivationConfiguration when you only need to present a single file, supporting multiple windows in your app without requiring custom window creation. ```swift class QLPreviewSceneActivationConfiguration { // Implementation details for preview scene activation configuration } ``` -------------------------------- ### Using ListStyle in SwiftUI Source: https://developer.apple.com/design/human-interface-guidelines/lists-and-tables Demonstrates how to apply different list styles in SwiftUI to adapt the appearance of lists based on platform conventions and data presentation needs. ```swift List { // Content } .listStyle(.plain) // Or .grouped, .inset, .insetGrouped, etc. ``` -------------------------------- ### Secure Text Field Example Source: https://developer.apple.com/design/human-interface-guidelines/text-fields Use secure text fields when your app asks for sensitive data, such as a password. This example demonstrates the basic usage of `SecureField` in SwiftUI. ```swift SecureField("Password", text: $password) ``` -------------------------------- ### Using `mixed` immersion style Source: https://developer.apple.com/design/human-interface-guidelines/immersive-experiences Prefer launching your app or game in the Shared Space or using the `mixed` immersion style. This allows users to reference your app while using other software and enables seamless switching. ```swift WindowGroup { ContentView() } .windowStyle(.volumetric) .supportedInteractions([.all]) .environment(\.mixedRealityImmersionStyle, .mixed) ``` -------------------------------- ### Transition from Any Item to New Window Source: https://developer.apple.com/design/human-interface-guidelines/windows Utilize UIWindowScene.ActivationInteraction to allow users to open content from various items into a new window, supporting flexible multitasking and context preservation. ```swift class UIWindowScene.ActivationInteraction { // Implementation details for scene activation interaction } ```