View
A type that represents part of your app’s user interface and provides modifiers that you use to configure views.
Declaration
@MainActor @preconcurrency protocol ViewMentioned in
Overview
You create custom views by declaring types that conform to the View protocol. Implement the required body computed property to provide the content for your custom view.
struct MyView: View {
var body: some View {
Text("Hello, World!")
}
}Assemble the view’s body by combining one or more of the built-in views provided by SwiftUI, like the Text instance in the example above, plus other custom views that you define, into a hierarchy of views. For more information about creating custom views, see Declaring a custom view.
The View protocol provides a set of modifiers — protocol methods with default implementations — that you use to configure views in the layout of your app. Modifiers work by wrapping the view instance on which you call them in another view with the specified characteristics, as described in Configuring views. For example, adding the opacity(_:) modifier to a text view returns a new view with some amount of transparency:
Text("Hello, World!")
.opacity(0.5) // Display partially transparent text.The complete list of default modifiers provides a large set of controls for managing views. For example, you can fine tune Layout modifiers, add Accessibility modifiers information, and respond to Input and event modifiers. You can also collect groups of default modifiers into new, custom view modifiers for easy reuse.
A type conforming to this protocol inherits @preconcurrency @MainActor isolation from the protocol if the conformance is declared in its original declaration. Isolation to the main actor is the default, but it’s not required. Declare the conformance in an extension to opt-out the isolation.
Topics
Implementing a custom view
Configuring view elements
Accessibility modifiersAppearance modifiersText and symbol modifiersAuxiliary view modifiersChart view modifiers
Drawing views
Providing interactivity
Deprecated modifiers
Instance Methods
accessibilityActions(category:_:)accessibilityDefaultFocus(_:_:)accessibilityScrollStatus(_:isEnabled:)addOrderToWalletButtonStyle(_:)addPassToWalletButtonStyle(_:)allowsWindowActivationEvents()appStoreMerchandising(isPresented:kind:onDismiss:)aspectRatio3D(_:contentMode:)assistiveAccessNavigationIcon(_:)assistiveAccessNavigationIcon(systemImage:)attributedTextFormattingDefinition(_:)automatedDeviceEnrollmentAddition(isPresented:)backgroundExtensionEffect()backgroundExtensionEffect(isEnabled:)breakthroughEffect(_:)buttonSizing(_:)certificateSheet(trust:title:message:help:)chart3DCameraProjection(_:)chart3DPose(_:)chart3DRenderingStyle(_:)chartZAxis(_:)chartZAxis(content:)chartZAxisLabel(_:position:alignment:spacing:)chartZScale(domain:range:type:)chartZScale(domain:type:)chartZScale(range:type:)chartZSelection(range:)chartZSelection(value:)contactAccessButtonCaption(_:)contactAccessButtonStyle(_:)contactAccessPicker(isPresented:completionHandler:)containerCornerOffset(_:sizeToFit:)containerValue(_:_:)contentCaptureProtected(_:)contentToolbar(for:content:)continuityDevicePicker(isPresented:onDidConnect:)controlWidgetActionHint(_:)controlWidgetStatus(_:)currentEntitlementTask(for:priority:action:)dialogPreventsAppTermination(_:)documentBrowserContextMenu(_:)dragConfiguration(_:)dragContainer(for:in:_:)dragContainer(for:itemID:in:_:)dragContainerSelection(_:containerNamespace:)dragPreviewsFormation(_:)draggable(_:containerNamespace:_:)draggable(_:id:containerNamespace:_:)draggable(_:id:item:containerNamespace:)draggable(_:item:containerNamespace:)draggable(containerItemID:containerNamespace:)dropConfiguration(_:)dropDestination(for:isEnabled:action:)dropPreviewsFormation(_:)familyActivityPicker(title:headerText:footerText:isPresented:selection:)formStyle(_:)foveatedStreamingPauseSheet(session:)gameSaveSyncingAlert(directory:finishedLoading:)glassBackgroundEffect(_:displayMode:)glassBackgroundEffect(_:in:displayMode:)glassEffect(_:in:)glassEffectID(_:in:)glassEffectTransition(_:)glassEffectUnion(id:namespace:)groupActivityAssociation(_:)handGestureShortcut(_:isEnabled:)handPointerBehavior(_:)handlesGameControllerEvents(matching:)handlesGameControllerEvents(matching:withOptions:)healthDataAccessRequest(store:objectType:predicate:trigger:completion:)healthDataAccessRequest(store:readTypes:trigger:completion:)healthDataAccessRequest(store:shareTypes:readTypes:trigger:completion:)imagePlaygroundGenerationStyle(_:in:)imagePlaygroundOptions(_:)imagePlaygroundPersonalizationPolicy(_:)imagePlaygroundSheet(isPresented:concept:sourceImage:onCompletion:onCancellation:)imagePlaygroundSheet(isPresented:concept:sourceImageURL:onCompletion:onCancellation:)imagePlaygroundSheet(isPresented:concepts:sourceImage:onCompletion:onCancellation:)imagePlaygroundSheet(isPresented:concepts:sourceImageURL:onCompletion:onCancellation:)immersiveEnvironmentPicker(content:)inAppPurchaseOptions(_:)journalingSuggestionsPicker(isPresented:journalingSuggestionToken:onCompletion:)journalingSuggestionsPicker(isPresented:onCompletion:)labelIconToTitleSpacing(_:)labelReservedIconWidth(_:)labeledContentStyle(_:)labelsVisibility(_:)lineHeight(_:)listRowInsets(_:_:)listSectionIndexVisibility(_:)listSectionMargins(_:_:)lookAroundViewer(isPresented:initialScene:allowsNavigation:showsRoadLabels:pointsOfInterest:onDismiss:)lookAroundViewer(isPresented:scene:allowsNavigation:showsRoadLabels:pointsOfInterest:onDismiss:)manageSubscriptionsSheet(isPresented:subscriptionGroupID:)managedContentStyle(_:)manipulable(coordinateSpace:operations:inertia:isEnabled:onChanged:)manipulable(transform:coordinateSpace:operations:inertia:isEnabled:onChanged:)manipulable(using:)manipulationGesture(updating:coordinateSpace:operations:inertia:isEnabled:onChanged:)mapCameraKeyframeAnimator(trigger:keyframes:)mapControlVisibility(_:)mapControls(_:)mapFeatureSelectionAccessory(_:)mapFeatureSelectionContent(content:)mapFeatureSelectionDisabled(_:)mapItemDetailPopover(isPresented:item:displaysMap:attachmentAnchor:)mapItemDetailPopover(isPresented:item:displaysMap:attachmentAnchor:arrowEdge:)mapItemDetailPopover(item:displaysMap:attachmentAnchor:)mapItemDetailPopover(item:displaysMap:attachmentAnchor:arrowEdge:)mapItemDetailSheet(isPresented:item:displaysMap:)mapItemDetailSheet(item:displaysMap:)mapScope(_:)mapStyle(_:)matchedTransitionSource(id:in:)matchedTransitionSource(id:in:configuration:)materialActiveAppearance(_:)navigationLinkIndicatorVisibility(_:)navigationTransition(_:)onAppIntentExecution(_:perform:)onApplePayCouponCodeChange(perform:)onApplePayPaymentMethodChange(perform:)onApplePayShippingContactChange(perform:)onApplePayShippingMethodChange(perform:)onCameraCaptureEvent(isEnabled:defaultSoundDisabled:action:)onCameraCaptureEvent(isEnabled:defaultSoundDisabled:primaryAction:secondaryAction:)onDragSessionUpdated(_:)onDropSessionUpdated(_:)onGeometryChange3D(for:of:action:)onInAppPurchaseCompletion(perform:)onInAppPurchaseStart(perform:)onInteractiveResizeChange(_:)onMapCameraChange(frequency:_:)onOpenURL(prefersInApp:)onWorldRecenter(action:)payLaterViewAction(_:)payLaterViewDisplayStyle(_:)payWithApplePayButtonDisableCardArt()payWithApplePayButtonStyle(_:)popoverTip(_:arrowEdge:action:)popoverTip(_:isPresented:attachmentAnchor:arrowEdge:action:)popoverTip(_:isPresented:attachmentAnchor:arrowEdges:action:)postToPhotosSharedAlbumSheet(isPresented:items:photoLibrary:defaultAlbumIdentifier:completion:)preferredSubscriptionOffer(_:)preferredSubscriptionPricingTerms(_:)preferredWindowClippingMargins(_:_:)presentationBreakthroughEffect(_:)presentationPreventsAppTermination(_:)productDescription(_:)productIconBorder()productViewStyle(_:)realityViewCameraControls(_:)realityViewLayoutBehavior(_:)rotation3DLayout(_:)rotation3DLayout(_:axis:)safeAreaBar(edge:alignment:spacing:content:)scaledToFill3D()scaledToFit3D()scrollEdgeEffectHidden(_:for:)scrollEdgeEffectStyle(_:for:)scrollInputBehavior(_:for:)searchSelection(_:)searchToolbarBehavior(_:)sectionIndexLabel(_:)signInWithAppleButtonStyle(_:)sliderThumbVisibility(_:)spatialOverlay(alignment:content:)spatialOverlayPreferenceValue(_:alignment:_:)storeButton(_:for:)storeProductTask(for:priority:action:)storeProductsTask(for:priority:action:)subscriptionIntroductoryOffer(applyOffer:compactJWS:)subscriptionOfferViewButtonVisibility(_:for:)subscriptionOfferViewDetailAction(_:)subscriptionOfferViewStyle(_:)subscriptionPromotionalOffer(offer:compactJWS:)subscriptionPromotionalOffer(offer:signature:)subscriptionStatusTask(for:priority:action:)subscriptionStoreButtonLabel(_:)subscriptionStoreControlBackground(_:)subscriptionStoreControlIcon(icon:)subscriptionStoreControlStyle(_:)subscriptionStoreControlStyle(_:placement:)subscriptionStoreOptionGroupStyle(_:)subscriptionStorePickerItemBackground(_:)subscriptionStorePickerItemBackground(_:in:)subscriptionStorePolicyDestination(for:destination:)subscriptionStorePolicyDestination(url:for:)subscriptionStorePolicyForegroundStyle(_:)subscriptionStorePolicyForegroundStyle(_:_:)subscriptionStoreSignInAction(_:)symbolColorRenderingMode(_:)symbolVariableValueMode(_:)tabBarMinimizeBehavior(_:)tabViewBottomAccessory(content:)tabViewBottomAccessory(isEnabled:content:)tabViewSearchActivation(_:)tabletopGame(_:parent:automaticUpdate:)tabletopGame(_:parent:automaticUpdate:interaction:)task(id:name:executorPreference:priority:file:line:_:)task(id:name:priority:file:line:_:)task(name:executorPreference:priority:file:line:action:)task(name:priority:file:line:_:)textContentType(_:)textInputFormattingControlVisibility(_:for:)textRenderer(_:)textSelectionAffinity(_:)tipAnchor(_:)tipBackground(_:)tipBackgroundInteraction(_:)tipCornerRadius(_:antialiased:)tipImageSize(_:)tipImageStyle(_:)tipImageStyle(_:_:)tipImageStyle(_:_:_:)tipViewStyle(_:)toolbarItemHidden(_:)transactionPicker(isPresented:selection:)transactionTask(_:action:)verifyIdentityWithWalletButtonStyle(_:)webViewBackForwardNavigationGestures(_:)webViewContentBackground(_:)webViewContextMenu(menu:)webViewElementFullscreenBehavior(_:)webViewLinkPreviews(_:)webViewMagnificationGestures(_:)webViewOnScrollGeometryChange(for:of:action:)webViewScrollInputBehavior(_:for:)webViewScrollPosition(_:)webViewTextSelection(_:)windowResizeAnchor(_:)windowToolbarFullScreenVisibility(_:)workoutPreview(_:isPresented:)writingDirection(strategy:)writingToolsAffordanceVisibility(_:)writingToolsBehavior(_:)