<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIView",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIView"
  },
  "title" : "UIView"
}
-->

# UIView

An object that manages the content for a rectangular area on the screen.

```
@MainActor class UIView
```

## Overview

Views are the fundamental building blocks of your app’s user interface, and the [`UIView`](/documentation/UIKit/UIView) class defines the behaviors that are common to all views. A view object renders content within its bounds rectangle, and handles any interactions with that content. The [`UIView`](/documentation/UIKit/UIView) class is a concrete class that you can instantiate and use to display a fixed background color. You can also subclass it to draw more sophisticated content. To display labels, images, buttons, and other interface elements commonly found in apps, use the view subclasses that the UIKit framework provides rather than trying to define your own.

Because view objects are the main way your application interacts with the user, they have a number of responsibilities. Here are just a few:

- Drawing and animation
  - Views draw content in their rectangular area using UIKit or Core Graphics.
  - You can animate some view properties to new values.
- Layout and subview management
  - Views may contain zero or more subviews.
  - Views can adjust the size and position of their subviews.
  - Use Auto Layout to define the rules for resizing and repositioning your views in response to changes in the view hierarchy.
- Event handling
  - A view is a subclass of [`UIResponder`](/documentation/UIKit/UIResponder) and can respond to touches and other types of events.
  - Views can install gesture recognizers to handle common gestures.

Views can nest inside other views to create view hierarchies, which offer a convenient way to organize related content. Nesting a view creates a parent-child relationship between the nested child view (known as the *subview*) and the parent (known as the *superview*). A parent view may contain any number of subviews, but each subview has only one superview. By default, when a subview’s visible area extends outside of the bounds of its superview, no clipping of the subview’s content occurs. Use the [`clipsToBounds`](/documentation/UIKit/UIView/clipsToBounds) property to change that behavior.

The [`frame`](/documentation/UIKit/UIView/frame) and [`bounds`](/documentation/UIKit/UIView/bounds) properties define the geometry of each view. The [`frame`](/documentation/UIKit/UIView/frame) property defines the origin and dimensions of the view in the coordinate system of its superview. The [`bounds`](/documentation/UIKit/UIView/bounds) property defines the internal dimensions of the view as it sees them, and its use is almost exclusive to custom drawing code. The center property provides a convenient way to reposition a view without changing its [`frame`](/documentation/UIKit/UIView/frame) or [`bounds`](/documentation/UIKit/UIView/bounds) properties directly.

### Create a view

Normally, you create views in your storyboards by dragging them from the library to your canvas. You can also create views programmatically. When creating a view, you typically specify its initial size and position relative to its future superview. For example, the following example creates a view and places its top-left corner at the point (10, 10) in the superview’s coordinate system (once it is added to that superview).

```objc
CGRect  viewRect = CGRectMake(10, 10, 100, 100);
UIView* myView = [[UIView alloc] initWithFrame:viewRect];
```

To add a subview to another view, call the [`addSubview(_:)`](/documentation/UIKit/UIView/addSubview(_:)) method on the superview. You may add any number of subviews to a view, and sibling views may overlap each other without any issues in iOS. Each call to the [`addSubview(_:)`](/documentation/UIKit/UIView/addSubview(_:)) method places the new view on top of all other siblings. You can specify the relative z-order of subview by adding it using the [`insertSubview(_:aboveSubview:)`](/documentation/UIKit/UIView/insertSubview(_:aboveSubview:)) and [`insertSubview(_:belowSubview:)`](/documentation/UIKit/UIView/insertSubview(_:belowSubview:)) methods. You can also exchange the position of already added subviews using the [`exchangeSubview(at:withSubviewAt:)`](/documentation/UIKit/UIView/exchangeSubview(at:withSubviewAt:)) method.

After creating a view, create Auto Layout rules to govern how the size and position of the view change in response to changes in the rest of the view hierarchy.

### Draw views

View drawing occurs on an as-needed basis. When a view is first shown, or when all or part of it becomes visible due to layout changes, the system asks the view to draw its contents. For views that contain custom content using UIKit or Core Graphics, the system calls the view’s [`draw(_:)`](/documentation/UIKit/UIView/draw(_:)) method. Your implementation of this method is responsible for drawing the view’s content into the current graphics context, which is set up by the system automatically prior to calling this method. This creates a static visual representation of your view’s content that can then be displayed on the screen.

When the actual content of your view changes, it’s your responsibility to notify the system that your view needs to be redrawn. You do this by calling your view’s [`setNeedsDisplay()`](/documentation/UIKit/UIView/setNeedsDisplay()) or [`setNeedsDisplay(_:)`](/documentation/UIKit/UIView/setNeedsDisplay(_:)) method of the view. These methods let the system know that it should update the view during the next drawing cycle. Because it waits until the next drawing cycle to update the view, you can call these methods on multiple views to update them at the same time.

### Animate views

Changes to several view properties can be animated — that is, changing the property creates an animation starting at the current value and ending at the new value that you specify. The following properties of the [`UIView`](/documentation/UIKit/UIView) class are animatable:

- [`frame`](/documentation/UIKit/UIView/frame)
- [`bounds`](/documentation/UIKit/UIView/bounds)
- [`center`](/documentation/UIKit/UIView/center)
- [`transform`](/documentation/UIKit/UIView/transform)
- [`alpha`](/documentation/UIKit/UIView/alpha)
- [`backgroundColor`](/documentation/UIKit/UIView/backgroundColor)

To animate your changes, create a [`UIViewPropertyAnimator`](/documentation/UIKit/UIViewPropertyAnimator) object and use its handler block to change the values of your view’s properties. The [`UIViewPropertyAnimator`](/documentation/UIKit/UIViewPropertyAnimator) class lets you specify the duration and timing of your animations, but it performs the actual animations. You can pause a property-based animator that’s currently running to interrupt the animation and drive it interactively. For more information, see [`UIViewPropertyAnimator`](/documentation/UIKit/UIViewPropertyAnimator).

### Threading considerations

Manipulations to your app’s user interface must occur on the main thread. Thus, you should always call the methods of the [`UIView`](/documentation/UIKit/UIView) class from code running in the main thread of your app. The only time this may not be strictly necessary is when creating the view object itself, but all other manipulations should occur on the main thread.

### Subclassing notes

The [`UIView`](/documentation/UIKit/UIView) class is a key subclassing point for visual content that also requires user interactions. Although there are many good reasons to subclass [`UIView`](/documentation/UIKit/UIView), it is recommended that you do so only when the basic [`UIView`](/documentation/UIKit/UIView) class or the standard system views do not provide the capabilities that you need. Subclassing requires more work on your part to implement the view and to tune its performance.

For information about ways to avoid subclassing, see [`Alternatives to subclassing`](/documentation/UIKit/UIView#Alternatives-to-subclassing).

#### Methods to override

When subclassing [`UIView`](/documentation/UIKit/UIView), there are only a handful of methods you should override and many methods that you might override depending on your needs. Because [`UIView`](/documentation/UIKit/UIView) is a highly configurable class, there are also many ways to implement sophisticated view behaviors without overriding custom methods, which are discussed in the Alternatives to Subclassing section. In the meantime, the following list includes the methods you might consider overriding in your [`UIView`](/documentation/UIKit/UIView) subclasses:

- Initialization:
  - [`init(frame:)`](/documentation/UIKit/UIView/init(frame:)) - It is recommended that you implement this method. You can also implement custom initialization methods in addition to, or instead of, this method.
  - [`init(coder:)`](/documentation/UIKit/UIView/init(coder:)) - Implement this method if you load your view from storyboards or nib files and your view requires custom initialization.
  - [`layerClass`](/documentation/UIKit/UIView/layerClass) Use this property only if you want your view to use a different Core Animation layer for its backing store. For example, if your view uses tiling to display a large scrollable area, you might want to set the property to the <doc://com.apple.documentation/documentation/QuartzCore/CATiledLayer> class.
- Drawing and printing:
  - [`draw(_:)`](/documentation/UIKit/UIView/draw(_:)) - Implement this method if your view draws custom content. If your view does not do any custom drawing, avoid overriding this method.
  - [`draw(_:for:)`](/documentation/UIKit/UIView/draw(_:for:)) - Implement this method only if you want to draw your view’s content differently during printing.
- Layout and Constraints:
  - [`requiresConstraintBasedLayout`](/documentation/UIKit/UIView/requiresConstraintBasedLayout) Use this property if your view class requires constraints to work properly.
  - [`updateConstraints()`](/documentation/UIKit/UIView/updateConstraints()) - Implement this method if your view needs to create custom constraints between your subviews.
  - [`alignmentRect(forFrame:)`](/documentation/UIKit/UIView/alignmentRect(forFrame:)), [`frame(forAlignmentRect:)`](/documentation/UIKit/UIView/frame(forAlignmentRect:)) - Implement these methods to override how your views are aligned to other views.
  - [`didAddSubview(_:)`](/documentation/UIKit/UIView/didAddSubview(_:)), [`willRemoveSubview(_:)`](/documentation/UIKit/UIView/willRemoveSubview(_:)) - Implement these methods as needed to track the additions and removals of subviews.
  - [`willMove(toSuperview:)`](/documentation/UIKit/UIView/willMove(toSuperview:)), [`didMoveToSuperview()`](/documentation/UIKit/UIView/didMoveToSuperview()) - Implement these methods as needed to track the movement of the current view in your view hierarchy.
- Event Handling:
  - [`gestureRecognizerShouldBegin(_:)`](/documentation/UIKit/UIView/gestureRecognizerShouldBegin(_:)) - Implement this method if your view handles touch events directly and might want to prevent attached gesture recognizers from triggering additional actions.
  - [`touchesBegan(_:with:)`](/documentation/UIKit/UIResponder/touchesBegan(_:with:)), [`touchesMoved(_:with:)`](/documentation/UIKit/UIResponder/touchesMoved(_:with:)), [`touchesEnded(_:with:)`](/documentation/UIKit/UIResponder/touchesEnded(_:with:)), [`touchesCancelled(_:with:)`](/documentation/UIKit/UIResponder/touchesCancelled(_:with:)) - Implement these methods if you need to handle touch events directly. (For gesture-based input, use gesture recognizers.)

#### Alternatives to subclassing

Many view behaviors can be configured without the need for subclassing. Before you start overriding methods, consider whether modifying the following properties or behaviors would provide the behavior you need.

- [`addConstraint(_:)`](/documentation/UIKit/UIView/addConstraint(_:)) - Define automatic layout behavior for the view and its subviews.
- [`autoresizingMask`](/documentation/UIKit/UIView/autoresizingMask-swift.property) - Provides automatic layout behavior when the superview’s frame changes. These behaviors can be combined with constraints.
- [`contentMode`](/documentation/UIKit/UIView/contentMode-swift.property) - Provides layout behavior for the view’s content, as opposed to the [`frame`](/documentation/UIKit/UIView/frame) of the view. This property also affects how the content is scaled to fit the view and whether it is cached or redrawn.
- [`isHidden`](/documentation/UIKit/UIView/isHidden) or [`alpha`](/documentation/UIKit/UIView/alpha) - Change the transparency of the view as a whole rather than hiding or applying alpha to your view’s rendered content.
- [`backgroundColor`](/documentation/UIKit/UIView/backgroundColor) - Set the view’s color rather than drawing that color yourself.
- Subviews - Rather than draw your content using a [`draw(_:)`](/documentation/UIKit/UIView/draw(_:)) method, embed image and label subviews with the content you want to present.
- Gesture recognizers - Rather than subclass to intercept and handle touch events yourself, you can use gesture recognizers to send an action to a target object.
- Animations - Use the built-in animation support rather than trying to animate changes yourself. The animation support provided by Core Animation is fast and easy to use.
- Image-based backgrounds - For views that display relatively static content, consider using a [`UIImageView`](/documentation/UIKit/UIImageView) object with gesture recognizers instead of subclassing and drawing the image yourself. Alternatively, you can also use a generic [`UIView`](/documentation/UIKit/UIView) object and assign your image as the content of the view’s <doc://com.apple.documentation/documentation/QuartzCore/CALayer> object.

Animations are another way to make visible changes to a view without requiring you to subclass and implement complex drawing code. Many properties of the [`UIView`](/documentation/UIKit/UIView) class are animatable, which means changes to those properties can trigger system-generated animations. Starting animations requires as little as one line of code to indicate that any changes that follow should be animated. For more information about animation support for views, see [`Animate views`](/documentation/UIKit/UIView#Animate-views).

### Sensor coordinate orientation

`UIView` conforms to <doc://com.apple.documentation/documentation/CoreLocation/CLBodyIdentifiable> and <doc://com.apple.documentation/documentation/CoreMotion/CMBodyIdentifiable>, informing Core Location and Core Motion how the app’s UI and this view are situated with respect to reference physical orientations. They use this information to transform the sensor values they provide, such as compass headings and device motion data, so those values align with your UI’s actual orientation. Without this association, Core Location and Core Motion report sensor values relative to the device’s physical orientation, which can produce unexpected results, such as a navigation map that appears rotated.

To use this approach, set any view as the body on a `CLLocationManager` or `CMMotionManager` instance. The system tracks orientation changes through the view and applies the correct transformation automatically.

```swift
let motionManager = CMMotionManager()

override func viewDidLoad() {
    super.viewDidLoad()
    motionManager.deviceMotionBody = view
}
```

## Topics

### Creating a view object

[`init(frame:)`](/documentation/UIKit/UIView/init(frame:))

Creates a view with the specified frame rectangle.

[`init(coder:)`](/documentation/UIKit/UIView/init(coder:))

Creates a view from data in an unarchiver.

### Configuring a view’s visual appearance

[`backgroundColor`](/documentation/UIKit/UIView/backgroundColor)

The view’s background color.

[`isHidden`](/documentation/UIKit/UIView/isHidden)

A Boolean value that determines whether the view is hidden.

[`alpha`](/documentation/UIKit/UIView/alpha)

The view’s alpha value.

[`isOpaque`](/documentation/UIKit/UIView/isOpaque)

A Boolean value that determines whether the view is opaque.

[`tintColor`](/documentation/UIKit/UIView/tintColor)

The first nondefault tint color value in the view’s hierarchy, ascending from and starting with the view itself.

[`tintAdjustmentMode`](/documentation/UIKit/UIView/tintAdjustmentMode-swift.property)

The first non-default tint adjustment mode value in the view’s hierarchy, ascending from and starting with the view itself.

[`clipsToBounds`](/documentation/UIKit/UIView/clipsToBounds)

A Boolean value that determines whether subviews are confined to the bounds of the view.

[`clearsContextBeforeDrawing`](/documentation/UIKit/UIView/clearsContextBeforeDrawing)

A Boolean value that determines whether the view’s bounds should be automatically cleared before drawing.

[`mask`](/documentation/UIKit/UIView/mask)

An optional view whose alpha channel is used to mask a view’s content.

[`layerClass`](/documentation/UIKit/UIView/layerClass)

Returns the class used to create the layer for instances of this class.

[`layer`](/documentation/UIKit/UIView/layer)

The view’s Core Animation layer to use for rendering.

### Configuring a view’s corners

[`cornerConfiguration`](/documentation/UIKit/UIView/cornerConfiguration-7l0ja)

A configuration that defines the corners of the view.

[`UICornerConfiguration`](/documentation/UIKit/UICornerConfiguration-swift.struct)

A configuration that defines how corner radii are mapped to the corners of a rectangle.

[`UICornerRadius`](/documentation/UIKit/UICornerRadius-swift.struct)

A type that represents the radius the system uses to round a corner.

[`cornerConfiguration`](/documentation/UIKit/UIView/cornerConfiguration-3m8ya)

A configuration that defines the corners of the view.

[`UICornerConfiguration`](/documentation/UIKit/UICornerConfiguration-c.class)

A configuration that defines how corner radii are mapped to the corners of a rectangle.

[`UICornerRadius`](/documentation/UIKit/UICornerRadius-c.class)

A type that represents the radius the system uses to round a corner.

[`effectiveRadius(corner:)`](/documentation/UIKit/UIView/effectiveRadius(corner:))

Returns the effective radius for the corner you provide, calculated using the view’s current corner configuration.

### Configuring the event-related behavior

[`isUserInteractionEnabled`](/documentation/UIKit/UIView/isUserInteractionEnabled)

A Boolean value that determines whether user events are ignored and removed from the event queue.

[`isMultipleTouchEnabled`](/documentation/UIKit/UIView/isMultipleTouchEnabled)

A Boolean value that indicates whether the view receives more than one touch at a time.

[`isExclusiveTouch`](/documentation/UIKit/UIView/isExclusiveTouch)

A Boolean value that indicates whether the receiver handles touch events exclusively.

### Configuring the bounds and frame rectangles

[`frame`](/documentation/UIKit/UIView/frame)

The frame rectangle, which describes the view’s location and size in its superview’s coordinate system.

[`bounds`](/documentation/UIKit/UIView/bounds)

The bounds rectangle, which describes the view’s location and size in its own coordinate system.

[`center`](/documentation/UIKit/UIView/center)

The center point of the view’s frame rectangle.

[`transform`](/documentation/UIKit/UIView/transform)

Specifies the transform applied to the view, relative to the center of its bounds.

[`transform3D`](/documentation/UIKit/UIView/transform3D)

The three-dimensional transform to apply to the view.

[`anchorPoint`](/documentation/UIKit/UIView/anchorPoint)

The anchor point of the view’s bounds rectangle.

### Managing the view hierarchy

[`superview`](/documentation/UIKit/UIView/superview)

The receiver’s superview, or `nil` if it has none.

[`subviews`](/documentation/UIKit/UIView/subviews)

The receiver’s immediate subviews.

[`window`](/documentation/UIKit/UIView/window)

The receiver’s window object, or `nil` if it has none.

[`addSubview(_:)`](/documentation/UIKit/UIView/addSubview(_:))

Adds a view to the end of the receiver’s list of subviews.

[`bringSubviewToFront(_:)`](/documentation/UIKit/UIView/bringSubviewToFront(_:))

Moves the specified subview so that it appears on top of its siblings.

[`sendSubviewToBack(_:)`](/documentation/UIKit/UIView/sendSubviewToBack(_:))

Moves the specified subview so that it appears behind its siblings.

[`removeFromSuperview()`](/documentation/UIKit/UIView/removeFromSuperview())

Unlinks the view from its superview and its window, and removes it from the responder chain.

[`insertSubview(_:at:)`](/documentation/UIKit/UIView/insertSubview(_:at:))

Inserts a subview at the specified index.

[`insertSubview(_:aboveSubview:)`](/documentation/UIKit/UIView/insertSubview(_:aboveSubview:))

Inserts a view above another view in the view hierarchy.

[`insertSubview(_:belowSubview:)`](/documentation/UIKit/UIView/insertSubview(_:belowSubview:))

Inserts a view below another view in the view hierarchy.

[`exchangeSubview(at:withSubviewAt:)`](/documentation/UIKit/UIView/exchangeSubview(at:withSubviewAt:))

Exchanges the subviews at the specified indices.

[`isDescendant(of:)`](/documentation/UIKit/UIView/isDescendant(of:))

Returns a Boolean value indicating whether the receiver is a subview of a given view or identical to that view.

### Observing view-related changes

[`didAddSubview(_:)`](/documentation/UIKit/UIView/didAddSubview(_:))

Tells the view that a subview was added.

[`willRemoveSubview(_:)`](/documentation/UIKit/UIView/willRemoveSubview(_:))

Tells the view that a subview is about to be removed.

[`willMove(toSuperview:)`](/documentation/UIKit/UIView/willMove(toSuperview:))

Tells the view that its superview is about to change to the specified superview.

[`didMoveToSuperview()`](/documentation/UIKit/UIView/didMoveToSuperview())

Tells the view that its superview changed.

[`willMove(toWindow:)`](/documentation/UIKit/UIView/willMove(toWindow:))

Tells the view that its window object is about to change.

[`didMoveToWindow()`](/documentation/UIKit/UIView/didMoveToWindow())

Tells the view that its window object changed.

### Observing trait changes

[`UITraitChangeObservable`](/documentation/UIKit/UITraitChangeObservable-67e94)

A type that calls your code in reaction to changes in the trait environment.

[`UITraitChangeObservable`](/documentation/UIKit/UITraitChangeObservable-7qoet)

A type that calls your code in reaction to changes in the trait environment.

### Requesting trait updates

[`updateTraitsIfNeeded()`](/documentation/UIKit/UIView/updateTraitsIfNeeded())

Forces an immediate trait update for this view (and its view controller, if applicable) and any subviews,
including any view controllers or views in its subtree. Any trait change callbacks are sent synchronously.

### Overriding trait values

[`traitOverrides`](/documentation/UIKit/UIView/traitOverrides-fd9z)

[`UITraitOverrides`](/documentation/UIKit/UITraitOverrides-swift.struct)

A mutable container of traits you use to set trait changes for an object and its descendants.

[`traitOverrides`](/documentation/UIKit/UIView/traitOverrides-2tqxk)

[`UITraitOverrides`](/documentation/UIKit/UITraitOverrides-c.protocol)

A mutable container of traits you use to set trait changes for an object and its descendants.

### Configuring content margins

[Positioning content within layout margins](/documentation/UIKit/positioning-content-within-layout-margins)

Position views so that they aren’t crowded by other content.

[`directionalLayoutMargins`](/documentation/UIKit/UIView/directionalLayoutMargins)

The default spacing to use when laying out content in a view, taking into account the current language direction.

[`layoutMargins`](/documentation/UIKit/UIView/layoutMargins)

The default spacing to use when laying out content in the view.

[`preservesSuperviewLayoutMargins`](/documentation/UIKit/UIView/preservesSuperviewLayoutMargins)

A Boolean value indicating whether the current view also respects the margins of its superview.

[`layoutMarginsDidChange()`](/documentation/UIKit/UIView/layoutMarginsDidChange())

Notifies the view that the layout margins changed.

### Getting the safe area

[Positioning content relative to the safe area](/documentation/UIKit/positioning-content-relative-to-the-safe-area)

Position views so that they aren’t obstructed by other content.

[`safeAreaInsets`](/documentation/UIKit/UIView/safeAreaInsets)

The insets that you use to determine the safe area for this view.

[`safeAreaLayoutGuide`](/documentation/UIKit/UIView/safeAreaLayoutGuide)

The layout guide representing the portion of your view that is unobscured by bars and other content.

[`safeAreaInsetsDidChange()`](/documentation/UIKit/UIView/safeAreaInsetsDidChange())

Called when the safe area of the view changes.

[`insetsLayoutMarginsFromSafeArea`](/documentation/UIKit/UIView/insetsLayoutMarginsFromSafeArea)

A Boolean value indicating whether the view’s layout margins are updated automatically to reflect the safe area.

### Managing the view’s constraints

Adjust the size and position of the view using Auto Layout constraints.

[`constraints`](/documentation/UIKit/UIView/constraints)

The constraints held by the view.

[`addConstraint(_:)`](/documentation/UIKit/UIView/addConstraint(_:))

Adds a constraint on the layout of the receiving view or its subviews.

[`addConstraints(_:)`](/documentation/UIKit/UIView/addConstraints(_:))

Adds multiple constraints on the layout of the receiving view or its subviews.

[`removeConstraint(_:)`](/documentation/UIKit/UIView/removeConstraint(_:))

Removes the specified constraint from the view.

[`removeConstraints(_:)`](/documentation/UIKit/UIView/removeConstraints(_:))

Removes the specified constraints from the view.

### Creating constraints using layout anchors

Attach Auto Layout constraints to one of the view’s anchors.

[`bottomAnchor`](/documentation/UIKit/UIView/bottomAnchor)

A layout anchor representing the bottom edge of the view’s frame.

[`centerXAnchor`](/documentation/UIKit/UIView/centerXAnchor)

A layout anchor representing the horizontal center of the view’s frame.

[`centerYAnchor`](/documentation/UIKit/UIView/centerYAnchor)

A layout anchor representing the vertical center of the view’s frame.

[`firstBaselineAnchor`](/documentation/UIKit/UIView/firstBaselineAnchor)

A layout anchor representing the baseline for the topmost line of text in the view.

[`heightAnchor`](/documentation/UIKit/UIView/heightAnchor)

A layout anchor representing the height of the view’s frame.

[`lastBaselineAnchor`](/documentation/UIKit/UIView/lastBaselineAnchor)

A layout anchor representing the baseline for the bottommost line of text in the view.

[`leadingAnchor`](/documentation/UIKit/UIView/leadingAnchor)

A layout anchor representing the leading edge of the view’s frame.

[`leftAnchor`](/documentation/UIKit/UIView/leftAnchor)

A layout anchor representing the left edge of the view’s frame.

[`rightAnchor`](/documentation/UIKit/UIView/rightAnchor)

A layout anchor representing the right edge of the view’s frame.

[`topAnchor`](/documentation/UIKit/UIView/topAnchor)

A layout anchor representing the top edge of the view’s frame.

[`trailingAnchor`](/documentation/UIKit/UIView/trailingAnchor)

A layout anchor representing the trailing edge of the view’s frame.

[`widthAnchor`](/documentation/UIKit/UIView/widthAnchor)

A layout anchor representing the width of the view’s frame.

### Working with layout guides

[`addLayoutGuide(_:)`](/documentation/UIKit/UIView/addLayoutGuide(_:))

Adds the specified layout guide to the view.

[`layoutGuides`](/documentation/UIKit/UIView/layoutGuides)

The array of layout guide objects owned by this view.

[`layoutMarginsGuide`](/documentation/UIKit/UIView/layoutMarginsGuide)

A layout guide representing the view’s margins.

[`readableContentGuide`](/documentation/UIKit/UIView/readableContentGuide)

A layout guide representing an area with a readable width within the view.

[`removeLayoutGuide(_:)`](/documentation/UIKit/UIView/removeLayoutGuide(_:))

Removes the specified layout guide from the view.

### Measuring in Auto Layout

[`systemLayoutSizeFitting(_:)`](/documentation/UIKit/UIView/systemLayoutSizeFitting(_:))

Returns the optimal size of the view based on its current constraints.

[`systemLayoutSizeFitting(_:withHorizontalFittingPriority:verticalFittingPriority:)`](/documentation/UIKit/UIView/systemLayoutSizeFitting(_:withHorizontalFittingPriority:verticalFittingPriority:))

Returns the optimal size of the view based on its constraints and the specified fitting priorities.

[`intrinsicContentSize`](/documentation/UIKit/UIView/intrinsicContentSize)

The natural size for the receiving view, considering only properties of the view itself.

[`invalidateIntrinsicContentSize()`](/documentation/UIKit/UIView/invalidateIntrinsicContentSize())

Invalidates the view’s intrinsic content size.

[`contentCompressionResistancePriority(for:)`](/documentation/UIKit/UIView/contentCompressionResistancePriority(for:))

Returns the priority with which a view resists being made smaller than its intrinsic size.

[`setContentCompressionResistancePriority(_:for:)`](/documentation/UIKit/UIView/setContentCompressionResistancePriority(_:for:))

Sets the priority with which a view resists being made smaller than its intrinsic size.

[`contentHuggingPriority(for:)`](/documentation/UIKit/UIView/contentHuggingPriority(for:))

Returns the priority with which a view resists being made larger than its intrinsic size.

[`setContentHuggingPriority(_:for:)`](/documentation/UIKit/UIView/setContentHuggingPriority(_:for:))

Sets the priority with which a view resists being made larger than its intrinsic size.

### Aligning views in Auto Layout

[`alignmentRect(forFrame:)`](/documentation/UIKit/UIView/alignmentRect(forFrame:))

Returns the view’s alignment rectangle for a given frame.

[`frame(forAlignmentRect:)`](/documentation/UIKit/UIView/frame(forAlignmentRect:))

Returns the view’s frame for a given alignment rectangle.

[`alignmentRectInsets`](/documentation/UIKit/UIView/alignmentRectInsets)

The insets from the view’s frame that define its alignment rectangle.

[`forFirstBaselineLayout`](/documentation/UIKit/UIView/forFirstBaselineLayout)

Returns a view used to satisfy first baseline constraints.

[`forLastBaselineLayout`](/documentation/UIKit/UIView/forLastBaselineLayout)

Returns a view used to satisfy last baseline constraints.

### Triggering Auto Layout

[`needsUpdateConstraints()`](/documentation/UIKit/UIView/needsUpdateConstraints())

A Boolean value that determines whether the view’s constraints need updating.

[`setNeedsUpdateConstraints()`](/documentation/UIKit/UIView/setNeedsUpdateConstraints())

Controls whether the view’s constraints need updating.

[`updateConstraints()`](/documentation/UIKit/UIView/updateConstraints())

Updates constraints for the view.

[`updateConstraintsIfNeeded()`](/documentation/UIKit/UIView/updateConstraintsIfNeeded())

Updates the constraints for the receiving view and its subviews.

### Debugging Auto Layout

[`constraintsAffectingLayout(for:)`](/documentation/UIKit/UIView/constraintsAffectingLayout(for:))

Returns the constraints impacting the layout of the view for a given axis.

[`hasAmbiguousLayout`](/documentation/UIKit/UIView/hasAmbiguousLayout)

A Boolean value that determines whether the constraints impacting the layout of the view incompletely specify the location of the view.

[`exerciseAmbiguityInLayout()`](/documentation/UIKit/UIView/exerciseAmbiguityInLayout())

Randomly changes the frame of a view with an ambiguous layout between the different valid values.

### Configuring the resizing behavior

Define how a view adjusts its content when its bounds change.

[`contentMode`](/documentation/UIKit/UIView/contentMode-swift.property)

A flag used to determine how a view lays out its content when its bounds change.

[`UIView.ContentMode`](/documentation/UIKit/UIView/ContentMode-swift.enum)

Options to specify how a view adjusts its content when its size changes.

[`sizeThatFits(_:)`](/documentation/UIKit/UIView/sizeThatFits(_:))

Asks the view to calculate and return the size that best fits the specified size.

[`sizeToFit()`](/documentation/UIKit/UIView/sizeToFit())

Resizes and moves the receiver view so it just encloses its subviews.

[`autoresizesSubviews`](/documentation/UIKit/UIView/autoresizesSubviews)

A Boolean value that determines whether the receiver automatically resizes its subviews when its bounds change.

[`autoresizingMask`](/documentation/UIKit/UIView/autoresizingMask-swift.property)

An integer bit mask that determines how the receiver resizes itself when its superview’s bounds change.

### Laying out subviews

Lay out views manually if your app doesn’t use Auto Layout.

[`layoutSubviews()`](/documentation/UIKit/UIView/layoutSubviews())

Lays out subviews.

[`setNeedsLayout()`](/documentation/UIKit/UIView/setNeedsLayout())

Invalidates the current layout of the receiver and triggers a layout update during the next update cycle.

[`layoutIfNeeded()`](/documentation/UIKit/UIView/layoutIfNeeded())

Lays out the subviews immediately, if layout updates are pending.

[`requiresConstraintBasedLayout`](/documentation/UIKit/UIView/requiresConstraintBasedLayout)

A Boolean value that indicates whether the receiver depends on the constraint-based layout system.

[`translatesAutoresizingMaskIntoConstraints`](/documentation/UIKit/UIView/translatesAutoresizingMaskIntoConstraints)

A Boolean value that determines whether the view’s autoresizing mask converts to Auto Layout constraints.

### Accessing insets and layout guides

[`UIView.LayoutRegion`](/documentation/UIKit/UIView/LayoutRegion)

[`UIViewLayoutRegion`](/documentation/UIKit/UIViewLayoutRegion)

[`UIViewLayoutRegionAdaptivityAxis`](/documentation/UIKit/UIViewLayoutRegionAdaptivityAxis)

[`directionalEdgeInsets(for:)`](/documentation/UIKit/UIView/directionalEdgeInsets(for:))

[`edgeInsets(for:)`](/documentation/UIKit/UIView/edgeInsets(for:))

[`layoutGuide(for:)`](/documentation/UIKit/UIView/layoutGuide(for:))

### Adjusting the user interface

[`overrideUserInterfaceStyle`](/documentation/UIKit/UIView/overrideUserInterfaceStyle)

The user interface style adopted by the view and all of its subviews.

[`semanticContentAttribute`](/documentation/UIKit/UIView/semanticContentAttribute)

A semantic description of the view’s contents, used to determine whether the view should be flipped when switching between left-to-right and right-to-left layouts.

[`effectiveUserInterfaceLayoutDirection`](/documentation/UIKit/UIView/effectiveUserInterfaceLayoutDirection)

The user interface layout direction appropriate for arranging the immediate content of the view.

[`userInterfaceLayoutDirection(for:)`](/documentation/UIKit/UIView/userInterfaceLayoutDirection(for:))

Returns the user interface direction for the given semantic content attribute.

[`userInterfaceLayoutDirection(for:relativeTo:)`](/documentation/UIKit/UIView/userInterfaceLayoutDirection(for:relativeTo:))

Returns the layout direction implied by the specified semantic content attribute, relative to the specified layout direction.

### Constraining views to the keyboard

[`keyboardLayoutGuide`](/documentation/UIKit/UIView/keyboardLayoutGuide)

A layout guide that tracks the keyboard’s position in your app’s layout.

### Adding and removing interactions

[`addInteraction(_:)`](/documentation/UIKit/UIView/addInteraction(_:))

Adds an interaction to the view.

[`removeInteraction(_:)`](/documentation/UIKit/UIView/removeInteraction(_:))

Removes an interaction from the view.

[`interactions`](/documentation/UIKit/UIView/interactions)

The array of interactions for the view.

[`UIInteraction`](/documentation/UIKit/UIInteraction)

The protocol that an interaction implements to access the view that owns it.

### Drawing and updating the view

[`draw(_:)`](/documentation/UIKit/UIView/draw(_:))

Draws the view’s image within the passed-in rectangle.

[`setNeedsDisplay()`](/documentation/UIKit/UIView/setNeedsDisplay())

Marks the receiver’s entire bounds rectangle as needing to be redrawn.

[`setNeedsDisplay(_:)`](/documentation/UIKit/UIView/setNeedsDisplay(_:))

Marks the specified rectangle of the receiver as needing to be redrawn.

[`contentScaleFactor`](/documentation/UIKit/UIView/contentScaleFactor)

The scale factor applied to the view.

[`tintColorDidChange()`](/documentation/UIKit/UIView/tintColorDidChange())

Called by the system when the tint color property changes.

### Updating the view when property values change

[`UIView.Invalidating`](/documentation/UIKit/UIView/Invalidating)

A property wrapper that notifies the system that a property value change has invalidated an aspect of the containing view.

[`UIViewInvalidating`](/documentation/UIKit/UIViewInvalidating)

Implements a type of invalidation that can occur on a view that requires an update.

### Formatting printed view content

[`viewPrintFormatter()`](/documentation/UIKit/UIView/viewPrintFormatter())

Returns a print formatter for the receiving view.

[`draw(_:for:)`](/documentation/UIKit/UIView/draw(_:for:))

Implemented to draw the view’s content for printing.

### Managing gesture recognizers

[`addGestureRecognizer(_:)`](/documentation/UIKit/UIView/addGestureRecognizer(_:))

Attaches a gesture recognizer to the view.

[`removeGestureRecognizer(_:)`](/documentation/UIKit/UIView/removeGestureRecognizer(_:))

Detaches a gesture recognizer from the receiving view.

[`gestureRecognizers`](/documentation/UIKit/UIView/gestureRecognizers)

The gesture-recognizer objects currently attached to the view.

[`gestureRecognizerShouldBegin(_:)`](/documentation/UIKit/UIView/gestureRecognizerShouldBegin(_:))

Asks the view if the gesture recognizer should continue tracking touch events.

### Working with focus

[`canBecomeFocused`](/documentation/UIKit/UIView/canBecomeFocused)

A Boolean value that indicates whether the view is currently capable of being focused.

[`inheritedAnimationDuration`](/documentation/UIKit/UIView/inheritedAnimationDuration)

Returns the inherited duration of the current animation.

[`isFocused`](/documentation/UIKit/UIView/isFocused)

A Boolean value that indicates whether the item is currently focused.

[`focusGroupIdentifier`](/documentation/UIKit/UIView/focusGroupIdentifier)

The identifier of the focus group that this view belongs to.

[`focusEffect`](/documentation/UIKit/UIView/focusEffect)

The visual effect to apply when the view becomes focused.

[`focusGroupPriority`](/documentation/UIKit/UIView/focusGroupPriority)

The importance of the item within a focus group, used by the focus system to determine the group’s primary item.

### Using motion effects

[`addMotionEffect(_:)`](/documentation/UIKit/UIView/addMotionEffect(_:))

Begins applying a motion effect to the view.

[`motionEffects`](/documentation/UIKit/UIView/motionEffects)

The array of motion effects for the view.

[`removeMotionEffect(_:)`](/documentation/UIKit/UIView/removeMotionEffect(_:))

Stops applying a motion effect to the view.

### Managing the hover appearance

[`hoverStyle`](/documentation/UIKit/UIView/hoverStyle)

The hover style for the view.

[`UIHoverStyle`](/documentation/UIKit/UIHoverStyle)

The hover style to apply to a view, including an effect and a shape to use for displaying that effect.

[`UIHoverEffectLayer`](/documentation/UIKit/UIHoverEffectLayer)

A layer type that can be used to apply a hover effect to its sublayers.

### Managing font-sizing preferences

[`minimumContentSizeCategory`](/documentation/UIKit/UIView/minimumContentSizeCategory)

The minimum content size category for the view and its subviews.

[`maximumContentSizeCategory`](/documentation/UIKit/UIView/maximumContentSizeCategory)

The maximum content size category for the view and its subviews.

[`appliedContentSizeCategoryLimitsDescription`](/documentation/UIKit/UIView/appliedContentSizeCategoryLimitsDescription)

A string that lists each of the view’s superviews, its content size category, and whether that view has content size category limits.

### Preserving and restoring state

[`restorationIdentifier`](/documentation/UIKit/UIView/restorationIdentifier)

The identifier that determines whether the view supports state restoration.

[`encodeRestorableState(with:)`](/documentation/UIKit/UIView/encodeRestorableState(with:))

Encodes state-related information for the view.

[`decodeRestorableState(with:)`](/documentation/UIKit/UIView/decodeRestorableState(with:))

Decodes and restores state-related information for the view.

### Capturing a view snapshot

[`snapshotView(afterScreenUpdates:)`](/documentation/UIKit/UIView/snapshotView(afterScreenUpdates:))

Returns a snapshot view based on the contents of the current view.

[`resizableSnapshotView(from:afterScreenUpdates:withCapInsets:)`](/documentation/UIKit/UIView/resizableSnapshotView(from:afterScreenUpdates:withCapInsets:))

Returns a snapshot view based on the specified contents of the current view, with stretchable insets.

[`drawHierarchy(in:afterScreenUpdates:)`](/documentation/UIKit/UIView/drawHierarchy(in:afterScreenUpdates:))

Renders a snapshot of the complete view hierarchy as visible onscreen into the current context.

### Identifying the view at runtime

[`tag`](/documentation/UIKit/UIView/tag)

An integer that you can use to identify view objects in your application.

[`viewWithTag(_:)`](/documentation/UIKit/UIView/viewWithTag(_:))

Returns the view whose tag matches the specified value.

### Converting between view coordinate systems

[`convert(_:to:)`](/documentation/UIKit/UIView/convert(_:to:)-1xizt)

Converts a point from the receiver’s coordinate system to that of the specified view.

[`convert(_:from:)`](/documentation/UIKit/UIView/convert(_:from:)-8neo1)

Converts a point from the coordinate system of a given view to that of the receiver.

[`convert(_:to:)`](/documentation/UIKit/UIView/convert(_:to:)-2kf3d)

Converts a rectangle from the receiver’s coordinate system to that of another view.

[`convert(_:from:)`](/documentation/UIKit/UIView/convert(_:from:)-7irzk)

Converts a rectangle from the coordinate system of another view to that of the receiver.

### Hit-testing in a view

[`hitTest(_:with:)`](/documentation/UIKit/UIView/hitTest(_:with:))

Returns the farthest descendant in the view hierarchy of the current view, including itself, that contains the specified point.

[`point(inside:with:)`](/documentation/UIKit/UIView/point(inside:with:))

Returns a Boolean value indicating whether the receiver contains the specified point.

### Ending a view-editing session

[`endEditing(_:)`](/documentation/UIKit/UIView/endEditing(_:))

Causes the view (or one of its embedded text fields) to resign the first responder status.

### Modifying the accessibility behavior

[`accessibilityIgnoresInvertColors`](/documentation/UIKit/UIView/accessibilityIgnoresInvertColors)

A Boolean value indicating whether the view ignores an accessibility request to invert its colors.

[`largeContentImage`](/documentation/UIKit/UIView/largeContentImage)

An image that represents the view in the large content viewer.

[`largeContentImageInsets`](/documentation/UIKit/UIView/largeContentImageInsets)

Insets to adjust the position of the view’s image so it appears centered in the large content viewer.

[`largeContentTitle`](/documentation/UIKit/UIView/largeContentTitle)

A string that describes the view in the large content viewer.

[`scalesLargeContentImage`](/documentation/UIKit/UIView/scalesLargeContentImage)

A Boolean value that indicates whether the large content viewer scales the item’s image to a larger size.

[`showsLargeContentViewer`](/documentation/UIKit/UIView/showsLargeContentViewer)

A Boolean value that indicates whether to show the view in the large content viewer.

### Animating views

[`animate(_:changes:completion:)`](/documentation/UIKit/UIView/animate(_:changes:completion:))

[`animate(springDuration:bounce:initialSpringVelocity:delay:options:animations:completion:)`](/documentation/UIKit/UIView/animate(springDuration:bounce:initialSpringVelocity:delay:options:animations:completion:))

Animates changes to one or more views using a spring animation with the specified duration, bounce, initial velocity, delay, options, and completion handler.

[`animateWithSpringDuration:bounce:initialSpringVelocity:delay:options:animations:completion:`](/documentation/UIKit/UIView/animateWithSpringDuration:bounce:initialSpringVelocity:delay:options:animations:completion:)

Animates changes to one or more views using a spring animation with the specified duration, bounce, initial velocity, delay, options, and completion handler.

[`animate(withDuration:delay:options:animations:completion:)`](/documentation/UIKit/UIView/animate(withDuration:delay:options:animations:completion:))

Animate changes to one or more views using the specified duration, delay, options, and completion handler.

[`animate(withDuration:animations:completion:)`](/documentation/UIKit/UIView/animate(withDuration:animations:completion:))

Animate changes to one or more views using the specified duration and completion handler.

[`animate(withDuration:animations:)`](/documentation/UIKit/UIView/animate(withDuration:animations:))

Animate changes to one or more views using the specified duration.

[`transition(with:duration:options:animations:completion:)`](/documentation/UIKit/UIView/transition(with:duration:options:animations:completion:))

Creates a transition animation for the specified container view.

[`transition(from:to:duration:options:completion:)`](/documentation/UIKit/UIView/transition(from:to:duration:options:completion:))

Creates a transition animation between the specified views using the given parameters.

[`animateKeyframes(withDuration:delay:options:animations:completion:)`](/documentation/UIKit/UIView/animateKeyframes(withDuration:delay:options:animations:completion:))

Creates an animation block object that can be used to set up keyframe-based animations for the current view.

[`addKeyframe(withRelativeStartTime:relativeDuration:animations:)`](/documentation/UIKit/UIView/addKeyframe(withRelativeStartTime:relativeDuration:animations:))

Specifies the timing and animation values for a single frame of a keyframe animation.

[`perform(_:on:options:animations:completion:)`](/documentation/UIKit/UIView/perform(_:on:options:animations:completion:))

Performs a specified system-provided animation on one or more views, along with optional parallel animations that you define.

[`animate(withDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:)`](/documentation/UIKit/UIView/animate(withDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:))

Performs a view animation using a timing curve corresponding to the motion of a physical spring.

[`performWithoutAnimation(_:)`](/documentation/UIKit/UIView/performWithoutAnimation(_:))

Disables a view transition animation.

[`modifyAnimations(withRepeatCount:autoreverses:animations:)`](/documentation/UIKit/UIView/modifyAnimations(withRepeatCount:autoreverses:animations:))

Repeats the specified animations a specific number of times, optionally running the animation forward and backward.

### Sensor coordinate orientation

  <doc://com.apple.documentation/documentation/CoreLocation/CLBodyIdentifiable>

  <doc://com.apple.documentation/documentation/CoreMotion/CMBodyIdentifiable>

### Constants

[`UIView.AnimationCurve`](/documentation/UIKit/UIView/AnimationCurve)

Specifies the supported animation curves.

[`UIView.AnimationOptions`](/documentation/UIKit/UIView/AnimationOptions)

Options for animating views using block objects.

[`UIView.AnimationTransition`](/documentation/UIKit/UIView/AnimationTransition)

Animation transition options for use in an animation block object.

[`UIView.SystemAnimation`](/documentation/UIKit/UIView/SystemAnimation)

Option to remove the views from the hierarchy when animation is complete.

[`UIView.KeyframeAnimationOptions`](/documentation/UIKit/UIView/KeyframeAnimationOptions)

Options for configuring keyframe-based animations.

[`NSLayoutConstraint.Axis`](/documentation/UIKit/NSLayoutConstraint/Axis)

Keys that specify a horizontal or vertical layout constraint between objects.

[`UIView.TintAdjustmentMode`](/documentation/UIKit/UIView/TintAdjustmentMode-swift.enum)

The tint adjustment mode for the view.

[`layoutFittingCompressedSize`](/documentation/UIKit/UIView/layoutFittingCompressedSize)

The option to use the smallest possible size.

[`layoutFittingExpandedSize`](/documentation/UIKit/UIView/layoutFittingExpandedSize)

The option to use the largest possible size.

[`noIntrinsicMetric`](/documentation/UIKit/UIView/noIntrinsicMetric)

The absence of an intrinsic metric for a given numeric view property.

[`UIView.AutoresizingMask`](/documentation/UIKit/UIView/AutoresizingMask-swift.struct)

Options for automatic view resizing.

[`UISemanticContentAttribute`](/documentation/UIKit/UISemanticContentAttribute)

A semantic description of the view’s contents, used to determine whether the view should be flipped when switching between left-to-right and right-to-left layouts.

### Deprecated

[Deprecated symbols](/documentation/UIKit/uiview-deprecated-symbols)

Symbols that views no longer support.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)