iOS Developer Library — Prerelease

Developer

UIKit Framework Reference UIView Class Reference

Options
Deployment Target:

On This Page
Language:

UIView

The UIView class defines a rectangular area on the screen and the interfaces for managing the content in that area. At runtime, a view object handles the rendering of any content in its area and also handles any interactions with that content. The UIView class itself provides basic behavior for filling its rectangular area with a background color. More sophisticated content can be presented by subclassing UIView and implementing the necessary drawing and event-handling code yourself. The UIKit framework also includes a set of standard subclasses that range from simple buttons to complex tables and can be used as-is. For example, a UILabel object draws a text string and a UIImageView object draws an image.

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 technologies such as UIKit, Core Graphics, and OpenGL ES.

    • Some view properties can be animated to new values.

  • Layout and subview management

    • A view may contain zero or more subviews.

    • Each view defines its own default resizing behavior in relation to its parent view.

    • A view can define the size and position of its subviews as needed.

  • Event handling

    • A view is a responder and can handle touch events and other events defined by the UIResponder class.

    • Views can use the addGestureRecognizer: method to install gesture recognizers to handle common gestures.

Views can embed other views and create sophisticated visual hierarchies. This creates a parent-child relationship between the view being embedded (known as the subview) and the parent view doing the embedding (known as the superview). Normally, a subview’s visible area is not clipped to the bounds of its superview, but in iOS you can use the clipsToBounds property to alter that behavior. A parent view may contain any number of subviews but each subview has only one superview, which is responsible for positioning its subviews appropriately.

The geometry of a view is defined by its frame, bounds, and center properties. The frame defines the origin and dimensions of the view in the coordinate system of its superview and is commonly used during layout to adjust the size or position of the view. The center property can be used to adjust the position of the view without changing its size. The bounds defines the internal dimensions of the view as it sees them and is used almost exclusively in custom drawing code. The size portion of the frame and bounds rectangles are coupled together so that changing the size of either rectangle updates the size of both.

For detailed information about how to use the UIView class, see View Programming Guide for iOS.

Creating a View

To create a view programmatically, you can use code like the following:

  1. CGRect viewRect = CGRectMake(10, 10, 100, 100);
  2. UIView* myView = [[UIView alloc] initWithFrame:viewRect];

This code creates the view and positions it at the point (10, 10) in its superview’s coordinate system (once it is added to that superview). To add a subview to another view, you use the addSubview: method. In iOS, sibling views may overlap each other without any issues, allowing complex view placement. The addSubview: method places the specified view on top of other siblings. You can specify the relative z-order of a subview by adding it using the insertSubview:aboveSubview: and insertSubview:belowSubview: methods. You can also exchange the position of already added subviews using the exchangeSubviewAtIndex:withSubviewAtIndex: method.

When creating a view, it is important to assign an appropriate value to the autoresizingMask property to ensure the view resizes correctly. View resizing primarily occurs when the orientation of your application’s interface changes but it may happen at other times as well. For example, calling the setNeedsLayout method forces your view to update its layout.

The View Drawing Cycle

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 drawRect: 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 is your responsibility to notify the system that your view needs to be redrawn. You do this by calling your view’s setNeedsDisplay or setNeedsDisplayInRect: 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.

For detailed information about the view drawing cycle and the role your views have in this cycle, see View Programming Guide for iOS.

Animations

Changes to several view properties can be animated—that is, changing the property creates an animation that conveys the change to the user over a short period of time. The UIView class does most of the work of performing the actual animations but you must still indicate which property changes you want to be animated. There are two different ways to initiate animations:

  • In iOS 4 and later, use the block-based animation methods. (Recommended)

  • Use the begin/commit animation methods.

The block-based animation methods (such as animateWithDuration:animations:) greatly simplify the creation of animations. With one method call, you specify the animations to be performed and the options for the animation. However, block-based animations are available only in iOS 4 and later. If your application runs on earlier versions of iOS, you must use the beginAnimations:context: and commitAnimations class methods to mark the beginning and ending of your animations.

The following properties of the UIView class are animatable:

For more information about how to configure animations, see View Programming Guide for iOS.

Threading Considerations

Manipulations to your application’s user interface must occur on the main thread. Thus, you should always call the methods of the UIView class from code running in the main thread of your application. 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 class is a key subclassing point for visual content that also requires user interactions. Although there are many good reasons to subclass UIView, it is recommended that you do so only when the basic 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.

Methods to Override

When subclassing UIView, there are only a handful of methods you should override and many methods that you might override depending on your needs. Because 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 subclasses:

  • Initialization:

    • initWithFrame: - It is recommended that you implement this method. You can also implement custom initialization methods in addition to, or instead of, this method.

    • initWithCoder: - Implement this method if you load your view from an Interface Builder nib file and your view requires custom initialization.

    • layerClass - Implement this method 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 override this method and return the CATiledLayer class.

  • Drawing and printing:

    • drawRect: - Implement this method if your view draws custom content. If your view does not do any custom drawing, avoid overriding this method.

    • drawRect:forViewPrintFormatter: - Implement this method only if you want to draw your view’s content differently during printing.

  • Constraints:

  • Layout:

    • sizeThatFits: - Implement this method if you want your view to have a different default size than it normally would during resizing operations. For example, you might use this method to prevent your view from shrinking to the point where subviews cannot be displayed correctly.

    • layoutSubviews - Implement this method if you need more precise control over the layout of your subviews than either the constraint or autoresizing behaviors provide.

    • didAddSubview:, willRemoveSubview: - Implement these methods as needed to track the additions and removals of subviews.

    • willMoveToSuperview:, didMoveToSuperview - Implement these methods as needed to track the movement of the current view in your view hierarchy.

    • willMoveToWindow:, didMoveToWindow - Implement these methods as needed to track the movement of your view to a different window.

  • Event Handling:

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: - Define automatic layout behavior for the view and its subviews.

  • autoresizingMask - Provides automatic layout behavior when the superview’s frame changes. These behaviors can be combined with constraints.

  • contentMode - Provides layout behavior for the view’s content, as opposed to the frame of the view. This property also affects how the content is scaled to fit the view and whether it is cached or redrawn.

  • contentStretch - Defines portions of the view as being stretchable. This behavior is typically used to implement buttons and other resizable views with sophisticated layout needs where redrawing the view every time would affect performance.

  • hidden or alpha - Change the transparency of the view as a whole rather than hiding or applying alpha to your view’s rendered content.

  • backgroundColor - Set the view’s color rather than drawing that color yourself.

  • Subviews - Rather than draw your content using a drawRect: 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 message 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 object with gesture recognizers instead of subclassing and drawing the image yourself. Alternatively, you can also use a generic UIView object and assign your image as the content of the view’s 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 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 Animations.

For more information about appearance and behavior configuration, see About Views in UIKit User Interface Catalog.

  • init(frame:) - initWithFrame: Designated Initializer

    Initializes and returns a newly allocated view object with the specified frame rectangle.

    Declaration

    Swift

    init(frame frame: CGRect)

    Objective-C

    - (instancetype nonnull)initWithFrame:(CGRect)aRect

    Parameters

    aRect

    The frame rectangle for the view, measured in points. The origin of the frame is relative to the superview in which you plan to add it. This method uses the frame rectangle to set the center and bounds properties accordingly.

    Return Value

    An initialized view object or nil if the object couldn't be created.

    Discussion

    The new view object must be inserted into the view hierarchy of a window before it can be used. If you create a view object programmatically, this method is the designated initializer for the UIView class. Subclasses can override this method to perform any custom initialization but must call super at the beginning of their implementation.

    If you use Interface Builder to design your interface, this method is not called when your view objects are subsequently loaded from the nib file. Objects in a nib file are reconstituted and then initialized using their initWithCoder: method, which modifies the attributes of the view to match the attributes stored in the nib file. For detailed information about how views are loaded from a nib file, see Resource Programming Guide.

    Availability

    Available in iOS 2.0 and later.

  • The view’s background color.

    Declaration

    Swift

    @NSCopying var backgroundColor: UIColor?

    Objective-C

    @property(nonatomic, copy) UIColor *backgroundColor

    Discussion

    Changes to this property can be animated. The default value is nil, which results in a transparent background color.

    Availability

    Available in iOS 2.0 and later.

    See Also

    alpha
    opaque

  • A Boolean value that determines whether the view is hidden.

    Declaration

    Swift

    var hidden: Bool

    Objective-C

    @property(nonatomic, getter=isHidden) BOOL hidden

    Discussion

    Setting the value of this property to YEStrue hides the receiver and setting it to NOfalse shows the receiver. The default value is NOfalse.

    A hidden view disappears from its window and does not receive input events. It remains in its superview’s list of subviews, however, and participates in autoresizing as usual. Hiding a view with subviews has the effect of hiding those subviews and any view descendants they might have. This effect is implicit and does not alter the hidden state of the receiver’s descendants.

    Hiding the view that is the window’s current first responder causes the view’s next valid key view to become the new first responder.

    The value of this property reflects the state of the receiver only and does not account for the state of the receiver’s ancestors in the view hierarchy. Thus this property can be NOfalse but the receiver may still be hidden if an ancestor is hidden.

    Availability

    Available in iOS 2.0 and later.

  • The view’s alpha value.

    Declaration

    Swift

    var alpha: CGFloat

    Objective-C

    @property(nonatomic) CGFloat alpha

    Discussion

    The value of this property is a floating-point number in the range 0.0 to 1.0, where 0.0 represents totally transparent and 1.0 represents totally opaque. This value affects only the current view and does not affect any of its embedded subviews.

    Changes to this property can be animated.

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that determines whether the view is opaque.

    Declaration

    Swift

    var opaque: Bool

    Objective-C

    @property(nonatomic, getter=isOpaque) BOOL opaque

    Discussion

    This property provides a hint to the drawing system as to how it should treat the view. If set to YEStrue, the drawing system treats the view as fully opaque, which allows the drawing system to optimize some drawing operations and improve performance. If set to NOfalse, the drawing system composites the view normally with other content. The default value of this property is YEStrue.

    An opaque view is expected to fill its bounds with entirely opaque content—that is, the content should have an alpha value of 1.0. If the view is opaque and either does not fill its bounds or contains wholly or partially transparent content, the results are unpredictable. You should always set the value of this property to NOfalse if the view is fully or partially transparent.

    You only need to set a value for the opaque property for subclasses of UIView that draw their own content using the drawRect: method. The opaque property has no effect for system provided classes such as UIButton, UILabel, UITableViewCell, etc.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    var tintColor: UIColor!

    Objective-C

    @property(nonatomic, strong) UIColor * __null_unspecified tintColor

    Discussion

    If the system cannot find a nondefault color in the hierarchy, this property’s value is a system-defined color instead.

    If the view’s tintAdjustmentMode property’s value is UIViewTintAdjustmentModeDimmed, then the tintColor property value is automatically dimmed.

    To refresh subview rendering when this property changes, override the tintColorDidChange method.

    Colors that are pattern colors (as described in UIColor Class Reference) are not supported.

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    var tintAdjustmentMode: UIViewTintAdjustmentMode

    Objective-C

    @property(nonatomic) UIViewTintAdjustmentMode tintAdjustmentMode

    Discussion

    When this property’s value is UIViewTintAdjustmentModeDimmed, the value of the tintColor property is modified to provide a dimmed appearance.

    If the system cannot find a non-default value in the subview hierarchy when you query this property, the value is UIViewTintAdjustmentModeNormal.

    When this property’s value changes (either by the view’s value changing or by one of its superview’s values changing), -the system calls the tintColorDidChange method to allow the view to refresh its rendering.

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    var clipsToBounds: Bool

    Objective-C

    @property(nonatomic) BOOL clipsToBounds

    Discussion

    Setting this value to YEStrue causes subviews to be clipped to the bounds of the receiver. If set to NOfalse, subviews whose frames extend beyond the visible bounds of the receiver are not clipped. The default value is NOfalse.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    var clearsContextBeforeDrawing: Bool

    Objective-C

    @property(nonatomic) BOOL clearsContextBeforeDrawing

    Discussion

    When set to YEStrue, the drawing buffer is automatically cleared to transparent black before the drawRect: method is called. This behavior ensures that there are no visual artifacts left over when the view’s contents are redrawn. If the view’s opaque property is also set to YEStrue, the backgroundColor property of the view must not be nil or drawing errors may occur. The default value of this property is YEStrue.

    If you set the value of this property to NOfalse, you are responsible for ensuring the contents of the view are drawn properly in your drawRect: method. If your drawing code is already heavily optimized, setting this property is NOfalse can improve performance, especially during scrolling when only a portion of the view might need to be redrawn.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    var maskView: UIView?

    Objective-C

    @property(nonatomic, strong) UIView *maskView

    Discussion

    The view’s alpha channel determines how much of the view’s content and background shows through. Fully or partially opaque pixels allow the underlying content to show through but fully transparent pixels block that content.

    Availability

    Available in iOS 8.0 and later.

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

    Declaration

    Swift

    class func layerClass() -> AnyClass

    Objective-C

    + (Class nonnull)layerClass

    Return Value

    The class used to create the view’s Core Animation layer.

    Discussion

    This method returns the CALayer class object by default. Subclasses can override this method and return a different layer class as needed. For example, if your view uses tiling to display a large scrollable area, you might want to override this method and return the CATiledLayer class.

    This method is called only once early in the creation of the view in order to create the corresponding layer object.

    Availability

    Available in iOS 2.0 and later.

    See Also

    layer

  • The view’s Core Animation layer used for rendering. (read-only)

    Declaration

    Swift

    var layer: CALayer { get }

    Objective-C

    @property(nonatomic, readonly, strong) CALayer *layer

    Discussion

    This property is never nil. The actual class of the object is determined by the value returned by the layerClass method. The view is the layer’s delegate.

    Availability

    Available in iOS 2.0 and later.

    See Also

    + layerClass

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

    Declaration

    Swift

    var userInteractionEnabled: Bool

    Objective-C

    @property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled

    Discussion

    When set to NOfalse, user events—such as touch and keyboard—intended for the view are ignored and removed from the event queue. When set to YEStrue, events are delivered to the view normally. The default value of this property is YEStrue.

    During an animation, user interactions are temporarily disabled for all views involved in the animation, regardless of the value in this property. You can disable this behavior by specifying the UIViewAnimationOptionAllowUserInteraction option when configuring the animation.

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that indicates whether the receiver handles multi-touch events.

    Declaration

    Swift

    var multipleTouchEnabled: Bool

    Objective-C

    @property(nonatomic, getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled

    Discussion

    When set to YEStrue, the receiver receives all touches associated with a multi-touch sequence. When set to NOfalse, the receiver receives only the first touch event in a multi-touch sequence. The default value of this property is NOfalse.

    Other views in the same window can still receive touch events when this property is NOfalse. If you want this view to handle multi-touch events exclusively, set the values of both this property and the exclusiveTouch property to YEStrue.

    Availability

    Available in iOS 2.0 and later.

    See Also

    exclusiveTouch

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

    Declaration

    Swift

    var exclusiveTouch: Bool

    Objective-C

    @property(nonatomic, getter=isExclusiveTouch) BOOL exclusiveTouch

    Discussion

    Setting this property to YEStrue causes the receiver to block the delivery of touch events to other views in the same window. The default value of this property is NOfalse.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    var frame: CGRect

    Objective-C

    @property(nonatomic) CGRect frame

    Discussion

    This rectangle defines the size and position of the view in its superview’s coordinate system. You use this rectangle during layout operations to size and position the view. Setting this property changes the point specified by the center property and the size in the bounds rectangle accordingly. The coordinates of the frame rectangle are always specified in points.

    Changing the frame rectangle automatically redisplays the receiver without invoking the drawRect: method. If you want the drawRect: method invoked when the frame rectangle changes, set the contentMode property to UIViewContentModeRedraw.

    Changes to this property can be animated. However, if the transform property contains a non-identity transform, the value of the frame property is undefined and should not be modified. In that case, you can reposition the view using the center property and adjust the size using the bounds property instead.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    var bounds: CGRect

    Objective-C

    @property(nonatomic) CGRect bounds

    Discussion

    On the screen, the bounds rectangle represents the same visible portion of the view as its frame rectangle. By default, the origin of the bounds rectangle is set to (0, 0) but you can change this value to display different portions of the view. The size of the bounds rectangle is coupled to the size of the frame rectangle, so that changes to one affect the other. Changing the bounds size grows or shrinks the view relative to its center point. The coordinates of the bounds rectangle are always specified in points.

    Changing the frame rectangle automatically redisplays the receiver without invoking the drawRect: method. If you want the drawRect: method invoked when the frame rectangle changes, set the contentMode property to UIViewContentModeRedraw.

    Changes to this property can be animated.

    The default bounds origin is (0,0) and the size is the same as the frame rectangle’s size.

    Availability

    Available in iOS 2.0 and later.

  • The center of the frame.

    Declaration

    Swift

    var center: CGPoint

    Objective-C

    @property(nonatomic) CGPoint center

    Discussion

    The center is specified within the coordinate system of its superview and is measured in points. Setting this property changes the values of the frame properties accordingly.

    Changing the frame rectangle automatically redisplays the receiver without invoking the drawRect: method. If you want the drawRect: method invoked when the frame rectangle changes, set the contentMode property to UIViewContentModeRedraw.

    Changes to this property can be animated. Use the beginAnimations:context: class method to begin and the commitAnimations class method to end an animation block.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    var transform: CGAffineTransform

    Objective-C

    @property(nonatomic) CGAffineTransform transform

    Discussion

    The origin of the transform is the value of the center property, or the layer’s anchorPoint property if it was changed. (Use the layer property to get the underlying Core Animation layer object.) The default value is CGAffineTransformIdentity.

    Changes to this property can be animated. Use the beginAnimations:context: class method to begin and the commitAnimations class method to end an animation block. The default is whatever the center value is (or anchor point if changed)

    Availability

    Available in iOS 2.0 and later.

  • The receiver’s superview, or nil if it has none. (read-only)

    Declaration

    Swift

    var superview: UIView? { get }

    Objective-C

    @property(nonatomic, readonly) UIView *superview

    Availability

    Available in iOS 2.0 and later.

  • The receiver’s immediate subviews. (read-only)

    Declaration

    Swift

    var subviews: [UIView] { get }

    Objective-C

    @property(nonatomic, readonly, copy) NSArray <__kindof UIView *> *subviews

    Discussion

    You can use this property to retrieve the subviews associated with your custom view hierarchies. The order of the subviews in the array reflects their visible order on the screen, with the view at index 0 being the back-most view.

    For complex views declared in UIKit and other system frameworks, any subviews of the view are generally considered private and subject to change at any time. Therefore, you should not attempt to retrieve or modify subviews for these types of system-supplied views. If you do, your code may break during a future system update.

    Availability

    Available in iOS 2.0 and later.

  • The receiver’s window object, or nil if it has none. (read-only)

    Declaration

    Swift

    var window: UIWindow? { get }

    Objective-C

    @property(nonatomic, readonly) UIWindow *window

    Discussion

    This property is nil if the view has not yet been added to a window.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func addSubview(_ view: UIView)

    Objective-C

    - (void)addSubview:(UIView * nonnull)view

    Parameters

    view

    The view to be added. After being added, this view appears on top of any other subviews.

    Discussion

    This method establishes a strong reference to view and sets its next responder to the receiver, which is its new superview.

    Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func bringSubviewToFront(_ view: UIView)

    Objective-C

    - (void)bringSubviewToFront:(UIView * nonnull)view

    Parameters

    view

    The subview to move to the front.

    Discussion

    This method moves the specified view to the end of the array of views in the subviews property.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func sendSubviewToBack(_ view: UIView)

    Objective-C

    - (void)sendSubviewToBack:(UIView * nonnull)view

    Parameters

    view

    The subview to move to the back.

    Discussion

    This method moves the specified view to the beginning of the array of views in the subviews property.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func removeFromSuperview()

    Objective-C

    - (void)removeFromSuperview

    Discussion

    If the view’s superview is not nil, the superview releases the view.

    Calling this method removes any constraints that refer to the view you are removing, or that refer to any view in the subtree of the view you are removing.

    Availability

    Available in iOS 2.0 and later.

  • Inserts a subview at the specified index.

    Declaration

    Swift

    func insertSubview(_ view: UIView, atIndex index: Int)

    Objective-C

    - (void)insertSubview:(UIView * nonnull)view atIndex:(NSInteger)index

    Parameters

    view

    The view to insert. This value cannot be nil.

    index

    The index in the array of the subviews property at which to insert the view. Subview indices start at 0 and cannot be greater than the number of subviews.

    Discussion

    This method establishes a strong reference to view and sets its next responder to the receiver, which is its new superview.

    Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview.

    Availability

    Available in iOS 2.0 and later.

  • Inserts a view above another view in the view hierarchy.

    Declaration

    Swift

    func insertSubview(_ view: UIView, aboveSubview siblingSubview: UIView)

    Objective-C

    - (void)insertSubview:(UIView * nonnull)view aboveSubview:(UIView * nonnull)siblingSubview

    Parameters

    view

    The view to insert. It’s removed from its superview if it’s not a sibling of siblingSubview.

    siblingSubview

    The sibling view that will be behind the inserted view.

    Discussion

    This method establishes a strong reference to view and sets its next responder to the receiver, which is its new superview.

    Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview.

    Availability

    Available in iOS 2.0 and later.

  • Inserts a view below another view in the view hierarchy.

    Declaration

    Swift

    func insertSubview(_ view: UIView, belowSubview siblingSubview: UIView)

    Objective-C

    - (void)insertSubview:(UIView * nonnull)view belowSubview:(UIView * nonnull)siblingSubview

    Parameters

    view

    The view to insert below another view. It’s removed from its superview if it’s not a sibling of siblingSubview.

    siblingSubview

    The sibling view that will be above the inserted view.

    Discussion

    This method establishes a strong reference to view and sets its next responder to the receiver, which is its new superview.

    Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview.

    Availability

    Available in iOS 2.0 and later.

  • Exchanges the subviews at the specified indices.

    Declaration

    Swift

    func exchangeSubviewAtIndex(_ index1: Int, withSubviewAtIndex index2: Int)

    Objective-C

    - (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2

    Parameters

    index1

    The index of the first subview in the receiver.

    index2

    The index of the second subview in the receiver.

    Discussion

    Each index represents the position of the corresponding view in the array in the subviews property. Subview indices start at 0 and cannot be greater than the number of subviews. This method does not change the superview of either view but simply swaps their positions in the subviews array.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func isDescendantOfView(_ view: UIView) -> Bool

    Objective-C

    - (BOOL)isDescendantOfView:(UIView * nonnull)view

    Parameters

    view

    The view to test against the receiver’s view hierarchy.

    Return Value

    YEStrue if the receiver is an immediate or distant subview of view or if view is the receiver itself; otherwise NOfalse.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    var autoresizingMask: UIViewAutoresizing

    Objective-C

    @property(nonatomic) UIViewAutoresizing autoresizingMask

    Discussion

    When a view’s bounds change, that view automatically resizes its subviews according to each subview’s autoresizing mask. You specify the value of this mask by combining the constants described in UIViewAutoresizing using the C bitwise OR operator. Combining these constants lets you specify which dimensions of the view should grow or shrink relative to the superview. The default value of this property is UIViewAutoresizingNone, which indicates that the view should not be resized at all.

    When more than one option along the same axis is set, the default behavior is to distribute the size difference proportionally among the flexible portions. The larger the flexible portion, relative to the other flexible portions, the more it is likely to grow. For example, suppose this property includes the UIViewAutoresizingFlexibleWidth and UIViewAutoresizingFlexibleRightMargin constants but does not include the UIViewAutoresizingFlexibleLeftMargin constant, thus indicating that the width of the view’s left margin is fixed but that the view’s width and right margin may change. Thus, the view appears anchored to the left side of its superview while both the view width and the gap to the right of the view increase.

    If the autoresizing behaviors do not offer the precise layout that you need for your views, you can use a custom container view and override its layoutSubviews method to position your subviews more precisely.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    var autoresizesSubviews: Bool

    Objective-C

    @property(nonatomic) BOOL autoresizesSubviews

    Discussion

    When set to YEStrue, the receiver adjusts the size of its subviews when its bounds change. The default value is YEStrue.

    Availability

    Available in iOS 2.0 and later.

    See Also

    autoresizingMask

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

    Declaration

    Swift

    var contentMode: UIViewContentMode

    Objective-C

    @property(nonatomic) UIViewContentMode contentMode

    Discussion

    The content mode specifies how the cached bitmap of the view’s layer is adjusted when the view’s bounds change. This property is often used to implement resizable controls, usually in conjunction with the contentStretch property. Instead of redrawing the contents of the view every time, you can use this property to specify that you want to scale the contents (either with or without distortion) or pin them to a particular spot on the view.

    For a list of values you can assign to this property, see UIViewContentMode. The default value of this property is UIViewContentModeScaleToFill.

    Availability

    Available in iOS 2.0 and later.

  • contentStretch (iOS 6.0) Property

    The rectangle that defines the stretchable and nonstretchable regions of a view.

    Declaration

    Objective-C

    @property(nonatomic) CGRect contentStretch

    Discussion

    You use this property to control how a view’s content is stretched to fill its bounds when the view is resized. Content stretching is often used to animate the resizing of a view. For example, buttons and other controls use stretching to maintain crisp borders while allowing the middle portions of the control to stretch and fill the available space.

    The values you specify for this rectangle must be normalized to the range 0.0 to 1.0. These values are then scaled to the size of the view’s content to obtain the appropriate pixel values. The default value for this rectangle has an origin of (0.0, 0.0) and a size of (1.0, 1.0). This reflects a rectangle whose stretchable portion encompasses the entire content.

    Availability

    Available in iOS 3.0 and later.

    Deprecated in iOS 6.0.

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

    Declaration

    Swift

    func sizeThatFits(_ size: CGSize) -> CGSize

    Objective-C

    - (CGSize)sizeThatFits:(CGSize)size

    Parameters

    size

    The size for which the view should calculate its best-fitting size.

    Return Value

    A new size that fits the receiver’s subviews.

    Discussion

    The default implementation of this method returns the existing size of the view. Subclasses can override this method to return a custom value based on the desired layout of any subviews. For example, a UISwitch object returns a fixed size value that represents the standard size of a switch view, and a UIImageView object returns the size of the image it is currently displaying.

    This method does not resize the receiver.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func sizeToFit()

    Objective-C

    - (void)sizeToFit

    Discussion

    Call this method when you want to resize the current view so that it uses the most appropriate amount of space. Specific UIKit views resize themselves according to their own internal needs. In some cases, if a view does not have a superview, it may size itself to the screen bounds. Thus, if you want a given view to size itself to its parent view, you should add it to the parent view before calling this method.

    You should not override this method. If you want to change the default sizing information for your view, override the sizeThatFits: instead. That method performs any needed calculations and returns them to this method, which then makes the change.

    Availability

    Available in iOS 2.0 and later.

  • Lays out subviews.

    Declaration

    Swift

    func layoutSubviews()

    Objective-C

    - (void)layoutSubviews

    Discussion

    The default implementation of this method does nothing on iOS 5.1 and earlier. Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subviews.

    Subclasses can override this method as needed to perform more precise layout of their subviews. You should override this method only if the autoresizing and constraint-based behaviors of the subviews do not offer the behavior you want. You can use your implementation to set the frame rectangles of your subviews directly.

    You should not call this method directly. If you want to force a layout update, call the setNeedsLayout method instead to do so prior to the next drawing update. If you want to update the layout of your views immediately, call the layoutIfNeeded method.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func setNeedsLayout()

    Objective-C

    - (void)setNeedsLayout

    Discussion

    Call this method on your application’s main thread when you want to adjust the layout of a view’s subviews. This method makes a note of the request and returns immediately. Because this method does not force an immediate update, but instead waits for the next update cycle, you can use it to invalidate the layout of multiple views before any of those views are updated. This behavior allows you to consolidate all of your layout updates to one update cycle, which is usually better for performance.

    Availability

    Available in iOS 2.0 and later.

  • Lays out the subviews immediately.

    Declaration

    Swift

    func layoutIfNeeded()

    Objective-C

    - (void)layoutIfNeeded

    Discussion

    Use this method to force the layout of subviews before drawing. Using the view that receives the message as the root view, this method lays out the view subtree starting at the root.

    Availability

    Available in iOS 2.0 and later.

  • Returns whether the receiver depends on the constraint-based layout system.

    Declaration

    Swift

    class func requiresConstraintBasedLayout() -> Bool

    Objective-C

    + (BOOL)requiresConstraintBasedLayout

    Return Value

    YEStrue if the view must be in a window using constraint-based layout to function properly, NOfalse otherwise.

    Discussion

    Custom views should override this to return YEStrue if they can not layout correctly using autoresizing.

    Availability

    Available in iOS 6.0 and later.

  • A Boolean value that determines whether the view’s autoresizing mask is translated into Auto Layout constraints.

    Declaration

    Swift

    var translatesAutoresizingMaskIntoConstraints: Bool

    Objective-C

    @property(nonatomic) BOOL translatesAutoresizingMaskIntoConstraints

    Discussion

    If this property’s value is YEStrue, the system creates a set of constraints that duplicate the behavior specified by the view’s autoresizing mask. This also lets you modify the view’s size and location using the view’s frame, bounds, or center properties, allowing you to create a static, frame-based layout within Auto Layout.

    Note that the autoresizing mask constraints fully specify the view’s size and position; therefore, you cannot add additional constraints to modify this size or position without introducing conflicts. If you want to use Auto Layout to dynamically calculate the size and position of your view, you must set this property to NOfalse, and then provide a nonambiguous, nonconflicting set of constraints for the view.

    By default, the property is set to YEStrue for any view you programmatically create. If you add views in Interface Builder, the system automatically sets this property to NOfalse.

    Availability

    Available in iOS 6.0 and later.

  • The constraints held by the view. (read-only)

    Declaration

    Swift

    var constraints: [NSLayoutConstraint] { get }

    Objective-C

    @property(nonatomic, readonly) NSArray <__kindof NSLayoutConstraint *> *constraints

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func addConstraint(_ constraint: NSLayoutConstraint)

    Objective-C

    - (void)addConstraint:(NSLayoutConstraint * nonnull)constraint

    Parameters

    constraint

    The constraint to be added to the view. The constraint may only reference the view itself or its subviews.

    Discussion

    The constraint must involve only views that are within scope of the receiving view. Specifically, any views involved must be either the receiving view itself, or a subview of the receiving view. Constraints that are added to a view are said to be held by that view. The coordinate system used when evaluating the constraint is the coordinate system of the view that holds the constraint.

    When developing for iOS 8.0 or later, set the constraint’s active property to YEStrue instead. This automatically adds the constraint to the correct view.

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func addConstraints(_ constraints: [NSLayoutConstraint])

    Objective-C

    - (void)addConstraints:(NSArray<__kindofNSLayoutConstraint *> * nonnull)constraints

    Parameters

    constraints

    An array of constraints to be added to the view. All constraints may only reference the view itself or its subviews.

    Discussion

    All constraints must involve only views that are within scope of the receiving view. Specifically, any views involved must be either the receiving view itself, or a subview of the receiving view. Constraints that are added to a view are said to be held by that view. The coordinate system used when evaluating each constraint is the coordinate system of the view that holds the constraint.

    When developing for iOS 8.0 or later, use the NSLayoutConstraint class’s activateConstraints: method instead. This automatically adds the constraints to the correct view.

    Availability

    Available in iOS 6.0 and later.

  • Removes the specified constraint from the view.

    Declaration

    Swift

    func removeConstraint(_ constraint: NSLayoutConstraint)

    Objective-C

    - (void)removeConstraint:(NSLayoutConstraint * nonnull)constraint

    Parameters

    constraint

    The constraint to remove. Removing a constraint not held by the view has no effect.

    Discussion

    When developing for iOS 8.0 or later, set the constraint’s active property to NOfalse instead. This automatically removes the constraint from the correct view.

    Availability

    Available in iOS 6.0 and later.

  • Removes the specified constraints from the view.

    Declaration

    Swift

    func removeConstraints(_ constraints: [NSLayoutConstraint])

    Objective-C

    - (void)removeConstraints:(NSArray<__kindofNSLayoutConstraint *> * nonnull)constraints

    Parameters

    constraints

    The constraints to remove.

    Discussion

    When developing for iOS 8.0 or later, use the NSLayoutConstraint class’s deactivateConstraints: method instead. This automatically removes the constraints from the correct view.

    Availability

    Available in iOS 6.0 and later.

  • Adds the provided layout guide to the view.

    Declaration

    Swift

    func addLayoutGuide(_ layoutGuide: UILayoutGuide)

    Objective-C

    - (void)addLayoutGuide:(UILayoutGuide * nonnull)layoutGuide

    Parameters

    layoutGuide

    The layout guide to be added.

    Discussion

    This method adds the provided layout guide to the end of the view’s layoutGuides array. It also assigns the view to the guide’s owningView property. Each guide can have only one owning view.

    Once the guide has been added to a view, it can participate in Auto Layout constraints with that view’s hierarchy.

    Availability

    Available in iOS 9.0 and later.

  • The array of layout guide objects owned by this view. (read-only)

    Declaration

    Swift

    var layoutGuides: [UILayoutGuide] { get }

    Objective-C

    @property(nonatomic, readonly, copy) NSArray <__kindof UILayoutGuide *> *layoutGuides

    Availability

    Available in iOS 9.0 and later.

  • A layout guide representing the view’s margins. (read-only)

    Declaration

    Swift

    var layoutMarginsGuide: UILayoutGuide { get }

    Objective-C

    @property(readonly, strong) UILayoutGuide *layoutMarginsGuide

    Discussion

    Use this layout guide’s anchors to create constraints with the view’s margin.

    Availability

    Available in iOS 9.0 and later.

    See Also

    layoutMargins

  • A layout guide representing an area with a readable width within the view. (read-only)

    Declaration

    Swift

    var readableContentGuide: UILayoutGuide { get }

    Objective-C

    @property(nonatomic, readonly, strong) UILayoutGuide *readableContentGuide

    Discussion

    This layout guide defines an area that can easily be read without forcing the user to move their head to track the lines. The readable content area follows the following rules:

    1. The readable content guide never extends beyond the view’s layout margin guide.

    2. If the readable content guide is vertically centered inside the layout margin guide.

    3. The readable content guide’s width is equal to or less than the readable width defined for the current dynamic text size.

    Use the readable content guide to lay out a single column of text. If you are laying out multiple columns, you can use the guide’s width to determine the optimal width for your columns.

    Availability

    Available in iOS 9.0 and later.

  • Removes the provided layout guide from the view.

    Declaration

    Swift

    func removeLayoutGuide(_ layoutGuide: UILayoutGuide)

    Objective-C

    - (void)removeLayoutGuide:(UILayoutGuide * nonnull)layoutGuide

    Parameters

    layoutGuide

    The layout guide to be removed.

    Discussion

    This method removes the provided layout guide from the view’s layoutGuides array. It also sets the guide’s owningView property to nil. Finally, it removes any constraints to the layout guide.

    Layout guides cannot participate in Auto Layout constraints unless they are added by a view in the view hierarchy.

    Availability

    Available in iOS 9.0 and later.

  • Returns the size of the view that satisfies the constraints it holds.

    Declaration

    Swift

    func systemLayoutSizeFittingSize(_ targetSize: CGSize) -> CGSize

    Objective-C

    - (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize

    Parameters

    targetSize

    Indicates whether you want the smallest or largest possible size that meets the constraints. See Fitting Size for accepted values.

    Return Value

    The size of the view that satisfies the constraints it holds.

    Discussion

    Determines the best size of the view considering all constraints it holds and those of its subviews.

    Availability

    Available in iOS 6.0 and later.

  • Returns the size of the view that satisfies the constraints it holds.

    Declaration

    Swift

    func systemLayoutSizeFittingSize(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority verticalFittingPriority: UILayoutPriority) -> CGSize

    Objective-C

    - (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize withHorizontalFittingPriority:(UILayoutPriority)horizontalFittingPriority verticalFittingPriority:(UILayoutPriority)verticalFittingPriority

    Parameters

    targetSize

    Indicates whether you want the smallest or largest possible size that meets the constraints. See Fitting Size for accepted values.

    horizontalFittingPriority

    The horizontal constraint priority.

    verticalFittingPriority

    The vertical constraint priority.

    Return Value

    The size of the view that satisfies the constraints it holds.

    Discussion

    Determines the best size of the view considering all constraints it holds and those of its subviews.

    Availability

    Available in iOS 8.0 and later.

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

    Declaration

    Swift

    func intrinsicContentSize() -> CGSize

    Objective-C

    - (CGSize)intrinsicContentSize

    Return Value

    A size indicating the natural size for the receiving view based on its intrinsic properties.

    Discussion

    Custom views typically have content that they display of which the layout system is unaware. Overriding this method allows a custom view to communicate to the layout system what size it would like to be based on its content. This intrinsic size must be independent of the content frame, because there’s no way to dynamically communicate a changed width to the layout system based on a changed height, for example.

    If a custom view has no intrinsic size for a given dimension, it can return UIViewNoIntrinsicMetric for that dimension.

    Availability

    Available in iOS 6.0 and later.

  • Invalidates the view’s intrinsic content size.

    Declaration

    Swift

    func invalidateIntrinsicContentSize()

    Objective-C

    - (void)invalidateIntrinsicContentSize

    Discussion

    Call this when something changes in your custom view that invalidates its intrinsic content size. This allows the constraint-based layout system to take the new intrinsic content size into account in its next layout pass.

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func contentCompressionResistancePriorityForAxis(_ axis: UILayoutConstraintAxis) -> UILayoutPriority

    Objective-C

    - (UILayoutPriority)contentCompressionResistancePriorityForAxis:(UILayoutConstraintAxis)axis

    Parameters

    axis

    The axis of the view that might be reduced.

    Return Value

    The priority with which the view should resist being compressed from its intrinsic size on the specified axis.

    Discussion

    The constraint-based layout system uses these priorities when determining the best layout for views that are encountering constraints that would require them to be smaller than their intrinsic size.

    Subclasses should not override this method. Instead, custom views should set default values for their content on creation, typically to NSLayoutPriorityDefaultLow or NSLayoutPriorityDefaultHigh.

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func setContentCompressionResistancePriority(_ priority: UILayoutPriority, forAxis axis: UILayoutConstraintAxis)

    Objective-C

    - (void)setContentCompressionResistancePriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis

    Parameters

    priority

    The new priority.

    axis

    The axis for which the compression resistance priority should be set.

    Discussion

    Custom views should set default values for both orientations on creation, based on their content, typically to NSLayoutPriorityDefaultLow or NSLayoutPriorityDefaultHigh. When creating user interfaces, the layout designer can modify these priorities for specific views when the overall layout design requires different tradeoffs than the natural priorities of the views being used in the interface.

    Subclasses should not override this method.

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func contentHuggingPriorityForAxis(_ axis: UILayoutConstraintAxis) -> UILayoutPriority

    Objective-C

    - (UILayoutPriority)contentHuggingPriorityForAxis:(UILayoutConstraintAxis)axis

    Parameters

    axis

    The axis of the view that might be enlarged.

    Return Value

    The priority with which the view should resist being enlarged from its intrinsic size on the specified axis.

    Discussion

    The constraint-based layout system uses these priorities when determining the best layout for views that are encountering constraints that would require them to be larger than their intrinsic size.

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func setContentHuggingPriority(_ priority: UILayoutPriority, forAxis axis: UILayoutConstraintAxis)

    Objective-C

    - (void)setContentHuggingPriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis

    Parameters

    priority

    The new priority.

    axis

    The axis for which the content hugging priority should be set.

    Discussion

    Custom views should set default values for both orientations on creation, based on their content, typically to NSLayoutPriorityDefaultLow or NSLayoutPriorityDefaultHigh. When creating user interfaces, the layout designer can modify these priorities for specific views when the overall layout design requires different tradeoffs than the natural priorities of the views being used in the interface.

    Subclasses should not override this method.

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func alignmentRectForFrame(_ frame: CGRect) -> CGRect

    Objective-C

    - (CGRect)alignmentRectForFrame:(CGRect)frame

    Parameters

    frame

    The frame whose corresponding alignment rectangle is desired.

    Return Value

    The alignment rectangle for the specified frame.

    Discussion

    The constraint-based layout system uses alignment rectangles to align views, rather than their frame. This allows custom views to be aligned based on the location of their content while still having a frame that encompasses any ornamentation they need to draw around their content, such as shadows or reflections.

    The default implementation returns the view’s frame modified by the view’s alignmentRectInsets. Most custom views can override alignmentRectInsets to specify the location of their content within their frame. Custom views that require arbitrary transformations can override alignmentRectForFrame: and frameForAlignmentRect: to describe the location of their content. These two methods must always be inverses of each other.

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func frameForAlignmentRect(_ alignmentRect: CGRect) -> CGRect

    Objective-C

    - (CGRect)frameForAlignmentRect:(CGRect)alignmentRect

    Parameters

    alignmentRect

    The alignment rectangle whose corresponding frame is desired.

    Return Value

    The frame for the specified alignment rectangle

    Discussion

    The constraint-based layout system uses alignment rectangles to align views, rather than their frame. This allows custom views to be aligned based on the location of their content while still having a frame that encompasses any ornamentation they need to draw around their content, such as shadows or reflections.

    The default implementation returns alignmentRect modified by the view’s alignmentRectInsets. Most custom views can override alignmentRectInsets to specify the location of their content within their frame. Custom views that require arbitrary transformations can override alignmentRectForFrame: and frameForAlignmentRect: to describe the location of their content. These two methods must always be inverses of each other.

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func alignmentRectInsets() -> UIEdgeInsets

    Objective-C

    - (UIEdgeInsets)alignmentRectInsets

    Return Value

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

    Discussion

    The default implementation of this method returns an NSEdgeInsets structure with zero values. Custom views that draw ornamentation around their content should override this method to return insets that align with the edges of the content, excluding the ornamentation. This allows the constraint-based layout system to align views based on their content, rather than just their frame.

    Custom views whose content location can’t be expressed by a simple set of insets should override alignmentRectForFrame: and frameForAlignmentRect: to describe their custom transform between alignment rectangle and frame.

    Availability

    Available in iOS 6.0 and later.

  • Returns a view used to satisfy baseline constraints.

    Declaration

    Swift

    func viewForBaselineLayout() -> UIView

    Objective-C

    - (UIView * nonnull)viewForBaselineLayout

    Return Value

    The view the constraint system should use to satisfy baseline constraints

    Discussion

    When you make a constraint on the NSLayoutAttributeBaseline of a view, the system aligns with the bottom of the view returned by this method. The default implementation returns the receiving view. If you override this method, the returned view must be a subview of the receiver.

    Availability

    Available in iOS 6.0 and later.

    Deprecated in iOS 9.0.

  • Returns a view used to satisfy first baseline constraints. (read-only)

    Declaration

    Swift

    var viewForFirstBaselineLayout: UIView { get }

    Objective-C

    @property(readonly, strong) UIView *viewForFirstBaselineLayout

    Discussion

    For views with multiple rows of text, the first baseline is the baseline for the topmost row.

    When you make a constraint on the NSLayoutAttributeFirstBaseline of a view, the system aligns with the bottom of the view returned by this method. The default implementation returns the receiving view. If you override this method, the returned view must be a subview of the receiver.

    Availability

    Available in iOS 9.0 and later.

  • Returns a view used to satisfy last baseline constraints. (read-only)

    Declaration

    Swift

    var viewForLastBaselineLayout: UIView { get }

    Objective-C

    @property(readonly, strong) UIView *viewForLastBaselineLayout

    Discussion

    For views with multiple rows of text, the last baseline is the baseline for the bottommost row.

    When you make a constraint on the NSLayoutAttributeLastBaseline of a view, the system aligns with the bottom of the view returned by this method. The default implementation returns the receiving view. If you override this method, the returned view must be a subview of the receiver.

    Availability

    Available in iOS 9.0 and later.

  • Returns whether the view’s constraints need updating.

    Declaration

    Swift

    func needsUpdateConstraints() -> Bool

    Objective-C

    - (BOOL)needsUpdateConstraints

    Return Value

    YEStrue if the view’s constraints need updating, NOfalse otherwise.

    Discussion

    The constraint-based layout system uses the return value of this method to determine whether it needs to call updateConstraints on your view as part of its normal layout pass.

    Availability

    Available in iOS 6.0 and later.

  • Controls whether the view’s constraints need updating.

    Declaration

    Swift

    func setNeedsUpdateConstraints()

    Objective-C

    - (void)setNeedsUpdateConstraints

    Discussion

    When a property of your custom view changes in a way that would impact constraints, you can call this method to indicate that the constraints need to be updated at some point in the future. The system will then call updateConstraints as part of its normal layout pass. Updating constraints all at once just before they are needed ensures that you don’t needlessly recalculate constraints when multiple changes are made to your view in between layout passes.

    Availability

    Available in iOS 6.0 and later.

  • Updates constraints for the view.

    Declaration

    Swift

    func updateConstraints()

    Objective-C

    - (void)updateConstraints

    Discussion

    Custom views that set up constraints themselves should do so by overriding this method. When your custom view notes that a change has been made to the view that invalidates one of its constraints, it should immediately remove that constraint, and then call setNeedsUpdateConstraints to note that constraints need to be updated. Before layout is performed, your implementation of updateConstraints will be invoked, allowing you to verify that all necessary constraints for your content are in place at a time when your custom view’s properties are not changing.

    You must not invalidate any constraints as part of your constraint update phase. You also must not invoke a layout or drawing phase as part of constraint updating.

    Availability

    Available in iOS 6.0 and later.

  • Updates the constraints for the receiving view and its subviews.

    Declaration

    Swift

    func updateConstraintsIfNeeded()

    Objective-C

    - (void)updateConstraintsIfNeeded

    Discussion

    Whenever a new layout pass is triggered for a view, the system invokes this method to ensure that any constraints for the view and its subviews are updated with information from the current view hierarchy and its constraints. This method is called automatically by the system, but may be invoked manually if you need to examine the most up to date constraints.

    Subclasses should not override this method.

    Availability

    Available in iOS 6.0 and later.

See Auto Layout Guide for more details on debugging constraint-based layout.

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

    Declaration

    Swift

    func constraintsAffectingLayoutForAxis(_ axis: UILayoutConstraintAxis) -> [NSLayoutConstraint]

    Objective-C

    - (NSArray<__kindofNSLayoutConstraint *> * nonnull)constraintsAffectingLayoutForAxis:(UILayoutConstraintAxis)axis

    Parameters

    axis

    The axis for which the constraints should be found.

    Return Value

    The constraints impacting the layout of the view for the specified axis.

    Discussion

    The returned set of constraints may not all include the view explicitly. Constraints that impact the location of the view implicitly may also be included. While this provides a good starting point for debugging, there is no guarantee that the returned set of constraints will include all of the constraints that have an impact on the view’s layout in the given orientation.

    This method should only be used for debugging constraint-based layout. No application should ship with calls to this method as part of its operation.

    Availability

    Available in iOS 6.0 and later.

  • Returns whether the constraints impacting the layout of the view incompletely specify the location of the view.

    Declaration

    Swift

    func hasAmbiguousLayout() -> Bool

    Objective-C

    - (BOOL)hasAmbiguousLayout

    Return Value

    YEStrue if the view’s location is incompletely specified, NOfalse otherwise.

    Discussion

    This method checks to see if there is any other frame the view could have that would also satisfy the constraints on the view. This is an expensive operation and is not run as part of the normal layout process, but can be useful when debugging whether a given interface has been specified with a sufficient number of constraints to ensure consistent layout.

    This method should only be used for debugging constraint-based layout. No application should ship with calls to this method as part of its operation.

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func exerciseAmbiguityInLayout()

    Objective-C

    - (void)exerciseAmbiguityInLayout

    Discussion

    This method randomly changes the frame of a view with an ambiguous layout between its different valid values, causing the view to move in the interface. This makes it easy to visually identify what the valid frames are and may enable the developer to discern what constraints need to be added to the layout to fully specify a location for the view.

    This method should only be used for debugging constraint-based layout. No application should ship with calls to this method as part of its operation.

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    var layoutMargins: UIEdgeInsets

    Objective-C

    @property(nonatomic) UIEdgeInsets layoutMargins

    Discussion

    Use this property so specify the desired amount of space (measured in points) between the edge of the view and any subviews. Auto layout uses your margins as a cue for placing content. For example, if you specify a set of horizontal constraints using the format string “|-[subview]-|”, the left and right edges of the subview are inset from the edge of the superview by the corresponding layout margins. When the edge of your view is close to the edge of the superview and the preservesSuperviewLayoutMargins property is YEStrue, the actual layout margins may be increased to prevent content from overlapping the superview’s margins.

    The default margins are eight points on each side.

    If the view is a view controller’s root view, then the system sets and manages the margins. The top and bottom margins are set to zero points. The side margins vary depending on the current size class, but can be either 16 or 20 points. You cannot change these margins.

    Availability

    Available in iOS 8.0 and later.

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

    Declaration

    Swift

    var preservesSuperviewLayoutMargins: Bool

    Objective-C

    @property(nonatomic) BOOL preservesSuperviewLayoutMargins

    Discussion

    When the value of this property is YEStrue, the superview’s margins are also considered when laying out content. This margin affects layouts where the distance between the edge of a view and its superview is smaller than the corresponding margin. For example, you might have a content view whose frame precisely matches the bounds of its superview. When any of the superview’s margins is inside the area represented by the content view and its own margins, UIKit adjusts the content view’s layout to respect the superview’s margins. The amount of the adjustment is the smallest amount needed to ensure that content is also inside the superview’s margins.

    The default value of this property is NOfalse.

    Availability

    Available in iOS 8.0 and later.

  • Notifies the view that the layout margins changed.

    Declaration

    Swift

    func layoutMarginsDidChange()

    Objective-C

    - (void)layoutMarginsDidChange

    Discussion

    The default implementation of this method does nothing. Subclasses can override this method and use it to respond when the value in the view’s layoutMargins property changes. For example, you might override this method if your view subclass handles layout manually or uses the layout margins during drawing. In both cases, you could use this method to initiate a drawing or layout update.

    Availability

    Available in iOS 8.0 and later.

  • Draws the receiver’s image within the passed-in rectangle.

    Declaration

    Swift

    func drawRect(_ rect: CGRect)

    Objective-C

    - (void)drawRect:(CGRect)rect

    Parameters

    rect

    The portion of the view’s bounds that needs to be updated. The first time your view is drawn, this rectangle is typically the entire visible bounds of your view. However, during subsequent drawing operations, the rectangle may specify only part of your view.

    Discussion

    The default implementation of this method does nothing. Subclasses that use technologies such as Core Graphics and UIKit to draw their view’s content should override this method and implement their drawing code there. You do not need to override this method if your view sets its content in other ways. For example, you do not need to override this method if your view just displays a background color or if your view sets its content directly using the underlying layer object.

    By the time this method is called, UIKit has configured the drawing environment appropriately for your view and you can simply call whatever drawing methods and functions you need to render your content. Specifically, UIKit creates and configures a graphics context for drawing and adjusts the transform of that context so that its origin matches the origin of your view’s bounds rectangle. You can get a reference to the graphics context using the UIGraphicsGetCurrentContext function, but do not establish a strong reference to the graphics context because it can change between calls to the drawRect: method.

    Similarly, if you draw using OpenGL ES and the GLKView class, GLKit configures the underlying OpenGL ES context appropriately for your view before calling this method (or the glkView:drawInRect: method of your GLKView delegate), so you can simply issue whatever OpenGL ES commands you need to render your content. For more information about how to draw using OpenGL ES, see OpenGL ES Programming Guide for iOS.

    You should limit any drawing to the rectangle specified in the rect parameter. In addition, if the opaque property of your view is set to YEStrue, your drawRect: method must totally fill the specified rectangle with opaque content.

    If you subclass UIView directly, your implementation of this method does not need to call super. However, if you are subclassing a different view class, you should call super at some point in your implementation.

    This method is called when a view is first displayed or when an event occurs that invalidates a visible part of the view. You should never call this method directly yourself. To invalidate part of your view, and thus cause that portion to be redrawn, call the setNeedsDisplay or setNeedsDisplayInRect: method instead.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func setNeedsDisplay()

    Objective-C

    - (void)setNeedsDisplay

    Discussion

    You can use this method or the setNeedsDisplayInRect: to notify the system that your view’s contents need to be redrawn. This method makes a note of the request and returns immediately. The view is not actually redrawn until the next drawing cycle, at which point all invalidated views are updated.

    You should use this method to request that a view be redrawn only when the content or appearance of the view change. If you simply change the geometry of the view, the view is typically not redrawn. Instead, its existing content is adjusted based on the value in the view’s contentMode property. Redisplaying the existing content improves performance by avoiding the need to redraw content that has not changed.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func setNeedsDisplayInRect(_ rect: CGRect)

    Objective-C

    - (void)setNeedsDisplayInRect:(CGRect)invalidRect

    Parameters

    invalidRect

    The rectangular region of the receiver to mark as invalid; it should be specified in the coordinate system of the receiver.

    Discussion

    You can use this method or the setNeedsDisplay to notify the system that your view’s contents need to be redrawn. This method adds the specified rectangle into the view’s current list of invalid rectangles and returns immediately. The view is not actually redrawn until the next drawing cycle, at which point all invalidated views are updated.

    You should use this method to request that a view be redrawn only when the content or appearance of the view change. If you simply change the geometry of the view, the view is typically not redrawn. Instead, its existing content is adjusted based on the value in the view’s contentMode property. Redisplaying the existing content improves performance by avoiding the need to redraw content that has not changed.

    Availability

    Available in iOS 2.0 and later.

  • The scale factor applied to the view.

    Declaration

    Swift

    var contentScaleFactor: CGFloat

    Objective-C

    @property(nonatomic) CGFloat contentScaleFactor

    Discussion

    The scale factor determines how content in the view is mapped from the logical coordinate space (measured in points) to the device coordinate space (measured in pixels). This value is typically either 1.0 or 2.0. Higher scale factors indicate that each point in the view is represented by more than one pixel in the underlying layer. For example, if the scale factor is 2.0 and the view frame size is 50 x 50 points, the size of the bitmap used to present that content is 100 x 100 pixels.

    The default value for this property is the scale factor associated with the screen currently displaying the view. If your custom view implements a custom drawRect: method and is associated with a window, or if you use the GLKView class to draw OpenGL ES content, your view draws at the full resolution of the screen. For system views, the value of this property may be 1.0 even on high resolution screens.

    In general, you should not need to modify the value in this property. However, if your application draws using OpenGL ES, you may want to change the scale factor to trade image quality for rendering performance. For more information on how to adjust your OpenGL ES rendering environment, see Supporting High-Resolution Displays in OpenGL ES Programming Guide for iOS.

    Availability

    Available in iOS 4.0 and later.

  • Called by the system when the tintColor property changes.

    Declaration

    Swift

    func tintColorDidChange()

    Objective-C

    - (void)tintColorDidChange

    Discussion

    The system calls this method on a view when your code changes the value of the tintColor property on that view. In addition, the system calls this method on a subview that inherits a changed interaction tint color.

    In your implementation, refresh the view rendering as needed.

    Availability

    Available in iOS 7.0 and later.

    See Also

    tintColor

  • Returns a print formatter for the receiving view.

    Declaration

    Swift

    func viewPrintFormatter() -> UIViewPrintFormatter

    Objective-C

    - (UIViewPrintFormatter * nonnull)viewPrintFormatter

    Return Value

    A UIViewPrintFormatter object or nil if the object could not be created. If it is successfully created, the returned object is automatically associated with this view.

    Discussion

    When initiating a print job, you can call this method to obtain an appropriate view print formatter object for your view. You can use the formatter object to configure the page layout options for your view during printing. Each time you call this method, you get a unique view print formatter object.

    For more information about how to use print formatters to configure the printing behavior of your view, see Drawing and Printing Guide for iOS.

    Availability

    Available in iOS 4.2 and later.

  • Implemented to draw the view’s content for printing.

    Declaration

    Swift

    func drawRect(_ rect: CGRect, forViewPrintFormatter formatter: UIViewPrintFormatter)

    Objective-C

    - (void)drawRect:(CGRect)area forViewPrintFormatter:(UIViewPrintFormatter * nonnull)formatter

    Parameters

    area

    A rectangle that defines the area for drawing printable content.

    formatter

    An instance of UIViewPrintFormatter obtained by calling the viewPrintFormatter method.

    Discussion

    You implement this method if you want a view’s printed content to appear differently than its displayed content. If you add a view print formatter to a print job but do not implement this method, the view’s drawRect: method is called to provide the content for printing.

    For more information about how to implement a custom drawing routine for printed content, see Drawing and Printing Guide for iOS.

    Availability

    Available in iOS 4.2 and later.

  • Attaches a gesture recognizer to the view.

    Declaration

    Swift

    func addGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer)

    Objective-C

    - (void)addGestureRecognizer:(UIGestureRecognizer * nonnull)gestureRecognizer

    Parameters

    gestureRecognizer

    An object whose class descends from the UIGestureRecognizer class. This parameter must not be nil.

    Discussion

    Attaching a gesture recognizer to a view defines the scope of the represented gesture, causing it to receive touches hit-tested to that view and all of its subviews. The view establishes a strong reference to the gesture recognizer.

    Availability

    Available in iOS 3.2 and later.

  • Detaches a gesture recognizer from the receiving view.

    Declaration

    Swift

    func removeGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer)

    Objective-C

    - (void)removeGestureRecognizer:(UIGestureRecognizer * nonnull)gestureRecognizer

    Parameters

    gestureRecognizer

    An object whose class descends from the UIGestureRecognizer class.

    Discussion

    This method releases gestureRecognizer in addition to detaching it from the view.

    Availability

    Available in iOS 3.2 and later.

  • The gesture-recognizer objects currently attached to the view.

    Declaration

    Swift

    var gestureRecognizers: [UIGestureRecognizer]?

    Objective-C

    @property(nonatomic, copy) NSArray <__kindof UIGestureRecognizer *> *gestureRecognizers

    Discussion

    Each of these objects is an instance of a subclass of the abstract base class UIGestureRecognizer. If there are no gesture recognizers attached, the value of this property is an empty array.

    Availability

    Available in iOS 3.2 and later.

  • Asks the view if the gesture recognizer should be allowed to continue tracking touch events.

    Declaration

    Swift

    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool

    Objective-C

    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer * nonnull)gestureRecognizer

    Parameters

    gestureRecognizer

    The gesture recognizer that is attempting to transition out of the UIGestureRecognizerStatePossible state.

    Return Value

    YEStrue if the gesture recognizer should continue tracking touch events and use them to trigger a gesture or NOfalse if it should transition to the UIGestureRecognizerStateFailed state.

    Discussion

    Subclasses may override this method and use it to prevent the recognition of particular gestures. For example, the UISlider class uses this method to prevent swipes parallel to the slider’s travel direction and that start in the thumb.

    At the time this method is called, the gesture recognizer is in the UIGestureRecognizerStatePossible state and thinks it has the events needed to move to the UIGestureRecognizerStateBegan state.

    The default implementation of this method returns YEStrue.

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    class func animateWithDuration(_ duration: NSTimeInterval, delay delay: NSTimeInterval, options options: UIViewAnimationOptions, animations animations: () -> Void, completion completion: ((Bool) -> Void)?)

    Objective-C

    + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^ nonnull)(void))animations completion:(void (^ nullable)(BOOL finished))completion

    Parameters

    duration

    The total duration of the animations, measured in seconds. If you specify a negative value or 0, the changes are made without animating them.

    delay

    The amount of time (measured in seconds) to wait before beginning the animations. Specify a value of 0 to begin the animations immediately.

    options

    A mask of options indicating how you want to perform the animations. For a list of valid constants, see UIViewAnimationOptions.

    animations

    A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be NULL.

    completion

    A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL.

    Discussion

    This method initiates a set of animations to perform on the view. The block object in the animations parameter contains the code for animating the properties of one or more views.

    During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.) If you want users to be able to interact with the views, include the UIViewAnimationOptionAllowUserInteraction constant in the options parameter.

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    class func animateWithDuration(_ duration: NSTimeInterval, animations animations: () -> Void, completion completion: ((Bool) -> Void)?)

    Objective-C

    + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^ nonnull)(void))animations completion:(void (^ nullable)(BOOL finished))completion

    Parameters

    duration

    The total duration of the animations, measured in seconds. If you specify a negative value or 0, the changes are made without animating them.

    animations

    A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be NULL.

    completion

    A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL.

    Discussion

    This method performs the specified animations immediately using the UIViewAnimationOptionCurveEaseInOut and UIViewAnimationOptionTransitionNone animation options.

    For example, if you want to fade a view until it is totally transparent and then remove it from your view hierarchy, you could use code similar to the following:

    1. [UIView animateWithDuration:0.2
    2. animations:^{view.alpha = 0.0;}
    3. completion:^(BOOL finished){ [view removeFromSuperview]; }];

    During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.)

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    class func animateWithDuration(_ duration: NSTimeInterval, animations animations: () -> Void)

    Objective-C

    + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^ nonnull)(void))animations

    Parameters

    duration

    The total duration of the animations, measured in seconds. If you specify a negative value or 0, the changes are made without animating them.

    animations

    A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be NULL.

    Discussion

    This method performs the specified animations immediately using the UIViewAnimationOptionCurveEaseInOut and UIViewAnimationOptionTransitionNone animation options.

    During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.)

    Availability

    Available in iOS 4.0 and later.

  • Creates a transition animation for the specified container view.

    Declaration

    Swift

    class func transitionWithView(_ view: UIView, duration duration: NSTimeInterval, options options: UIViewAnimationOptions, animations animations: () -> Void, completion completion: ((Bool) -> Void)?)

    Objective-C

    + (void)transitionWithView:(UIView * nonnull)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ nonnull)(void))animations completion:(void (^ nullable)(BOOL finished))completion

    Parameters

    view

    The container view that performs the transition.

    duration

    The duration of the transition animation, measured in seconds. If you specify a negative value or 0, the transition is made without animations.

    options

    A mask of options indicating how you want to perform the animations. For a list of valid constants, see UIViewAnimationOptions.

    animations

    A block object that contains the changes you want to make to the specified view. This block takes no parameters and has no return value. This parameter must not be NULL.

    completion

    A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL.

    Discussion

    This method applies a transition to the specified view so that you can make state changes to it. The block you specify in the animations parameter contains whatever state changes you want to make. You can use this block to add, remove, show, or hide subviews of the specified view. If you want to incorporate other animatable changes, you must include the UIViewAnimationOptionAllowAnimatedContent key in the options parameter.

    The following code creates a flip transition for the specified container view. At the appropriate point in the transition, one subview is removed and another is added to the container view. This makes it look as if a new view was flipped into place with the new subview, but really it is just the same view animated back into place with a new configuration.

    1. [UIView transitionWithView:containerView
    2. duration:0.2
    3. options:UIViewAnimationOptionTransitionFlipFromLeft
    4. animations:^{ [fromView removeFromSuperview]; [containerView addSubview:toView]; }
    5. completion:NULL];

    During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.) If you want users to be able to interact with the views, include the UIViewAnimationOptionAllowUserInteraction constant in the options parameter.

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    class func transitionFromView(_ fromView: UIView, toView toView: UIView, duration duration: NSTimeInterval, options options: UIViewAnimationOptions, completion completion: ((Bool) -> Void)?)

    Objective-C

    + (void)transitionFromView:(UIView * nonnull)fromView toView:(UIView * nonnull)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^ nullable)(BOOL finished))completion

    Parameters

    fromView

    The starting view for the transition. By default, this view is removed from its superview as part of the transition.

    toView

    The ending view for the transition. By default, this view is added to the superview of fromView as part of the transition.

    duration

    The duration of the transition animation, measured in seconds. If you specify a negative value or 0, the transition is made without animations.

    options

    A mask of options indicating how you want to perform the animations. For a list of valid constants, see UIViewAnimationOptions.

    completion

    A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL.

    Discussion

    This method provides a simple way to transition from the view in the fromView parameter to the view in the toView parameter. By default, the view in fromView is replaced in the view hierarchy by the view in toView. If both views are already part of your view hierarchy, you can include the UIViewAnimationOptionShowHideTransitionViews option in the options parameter to simply hide or show them.

    This method modifies the views in their view hierarchy only. It does not modify your application’s view controllers in any way. For example, if you use this method to change the root view displayed by a view controller, it is your responsibility to update the view controller appropriately to handle the change.

    The view transition starts immediately unless another animation is already in-flight, in which case it starts immediately after the current animation finishes.

    During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.) If you want users to be able to interact with the views, include the UIViewAnimationOptionAllowUserInteraction constant in the options parameter.

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    class func animateKeyframesWithDuration(_ duration: NSTimeInterval, delay delay: NSTimeInterval, options options: UIViewKeyframeAnimationOptions, animations animations: () -> Void, completion completion: ((Bool) -> Void)?)

    Objective-C

    + (void)animateKeyframesWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)options animations:(void (^ nonnull)(void))animations completion:(void (^ nullable)(BOOL finished))completion

    Parameters

    duration

    The duration of the overall animation, measured in seconds. If you specify a negative value or 0, changes are made immediately and without animations.

    delay

    Specifies the time (in seconds) to wait before starting the animation.

    options

    A mask of options indicating how you want to perform the animations. For a list of valid constants, see “UIViewKeyframeAnimationOptions”.

    animations

    A block object containing the changes to commit to the views. Typically, you call the addKeyframeWithRelativeStartTime:relativeDuration:animations: method one or more times from inside this block. You may also change view values directly if you want those changes to animate over the full duration. This block takes no parameters and has no return value. Do not use a nil value for this parameter.

    completion

    A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. You can use a nil value for this parameter.

    Discussion

    This method creates an animation block that you can use to set up a keyframe-based animation. The keyframes themselves are not part of the initial animation block you create using this method. Inside the animations block, you must add the keyframe time and animation data by calling the addKeyframeWithRelativeStartTime:relativeDuration:animations: method one or more times. Adding keyframes causes the animation to animate the view from its current value to the value of the first keyframe, then to the value of the next keyframe, and so on at the times you specify.

    If you do not add any keyframes in the animations block, the animation proceeds from start to end like a standard animation block. In other words, the system animates from the current view values to any new values over the specified duration.

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func addKeyframeWithRelativeStartTime(_ frameStartTime: Double, relativeDuration frameDuration: Double, animations animations: () -> Void)

    Objective-C

    + (void)addKeyframeWithRelativeStartTime:(double)frameStartTime relativeDuration:(double)frameDuration animations:(void (^ nonnull)(void))animations

    Parameters

    frameStartTime

    The time at which to start the specified animations. This value must be in the range 0 to 1, where 0 represents the start of the overall animation and 1 represents the end of the overall animation. For example, for an animation that is two seconds in duration, specifying a start time of 0.5 causes the animations to begin executing one second after the start of the overall animation.

    frameDuration

    The length of time over which to animate to the specified value. This value must be in the range 0 to 1 and indicates the amount of time relative to the overall animation length. If you specify a value of 0, any properties you set in the animations block update immediately at the specified start time. If you specify a nonzero value, the properties animate over that amount of time. For example, for an animation that is two seconds in duration, specifying a duration of 0.5 results in an animation duration of one second.

    animations

    A block object containing the animations you want to perform. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be nil.

    Discussion

    To animate view properties during a keyframe animation, call this method from within the animation block you pass to the animateKeyframesWithDuration:delay:options:animations:completion: method. To animate between different values, or to tweak the timing of your view property animations, you can call this method multiple times within a block.

    The view properties you change in the animations block animate over the timespan you specify in frameDuration parameter. The properties do not begin animating until the time you specify in the frameStartTime parameter. After the frame start time, the animation executes over its specified duration or until interrupted by another animation.

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func performSystemAnimation(_ animation: UISystemAnimation, onViews views: [UIView], options options: UIViewAnimationOptions, animations parallelAnimations: (() -> Void)?, completion completion: ((Bool) -> Void)?)

    Objective-C

    + (void)performSystemAnimation:(UISystemAnimation)animation onViews:(NSArray<__kindof UIView *> * nonnull)views options:(UIViewAnimationOptions)options animations:(void (^ nullable)(void))parallelAnimations completion:(void (^ nullable)(BOOL finished))completion

    Parameters

    animation

    The system animation to perform; a constant from the UISystemAnimation enum.

    views

    The views to perform the animations on.

    options

    A mask of options indicating how you want to perform the animations. For a list of valid constants, see UIViewAnimationOptions.

    parallelAnimations

    Additional animations you specify to run alongside the system animation, with the same timing and duration that the system animation defines or inherits.

    In your additional animations, do not modify properties of the view on which the system animation is being performed.

    completion

    A block object to be executed when the animation sequence ends. The single Boolean argument indicates whether or not the animations finished before the completion handler was called. If the animation duration is 0, this block is performed at the beginning of the next run-loop cycle. You can use a nil value for this parameter.

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func animateWithDuration(_ duration: NSTimeInterval, delay delay: NSTimeInterval, usingSpringWithDamping dampingRatio: CGFloat, initialSpringVelocity velocity: CGFloat, options options: UIViewAnimationOptions, animations animations: () -> Void, completion completion: ((Bool) -> Void)?)

    Objective-C

    + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^ nonnull)(void))animations completion:(void (^ nullable)(BOOL finished))completion

    Parameters

    duration

    The total duration of the animations, measured in seconds. If you specify a negative value or 0, the changes are made without animating them.

    delay

    The amount of time (measured in seconds) to wait before beginning the animations. Specify a value of 0 to begin the animations immediately.

    dampingRatio

    The damping ratio for the spring animation as it approaches its quiescent state.

    To smoothly decelerate the animation without oscillation, use a value of 1. Employ a damping ratio closer to zero to increase oscillation.

    velocity

    The initial spring velocity. For smooth start to the animation, match this value to the view’s velocity as it was prior to attachment.

    A value of 1 corresponds to the total animation distance traversed in one second. For example, if the total animation distance is 200 points and you want the start of the animation to match a view velocity of 100 pt/s, use a value of 0.5.

    options

    A mask of options indicating how you want to perform the animations. For a list of valid constants, see UIViewAnimationOptions.

    animations

    A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be NULL.

    completion

    A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL.

    Discussion

    Availability

    Available in iOS 7.0 and later.

  • Disables a view transition animation.

    Declaration

    Swift

    class func performWithoutAnimation(_ actionsWithoutAnimation: () -> Void)

    Objective-C

    + (void)performWithoutAnimation:(void (^ nonnull)(void))actionsWithoutAnimation

    Parameters

    actionsWithoutAnimation

    The view transition code that you want to perform without animation.

    Availability

    Available in iOS 7.0 and later.

Use of the methods in this section is discouraged in iOS 4 and later. Use the block-based animation methods instead.

  • Begins applying a motion effect to the view.

    Declaration

    Swift

    func addMotionEffect(_ effect: UIMotionEffect)

    Objective-C

    - (void)addMotionEffect:(UIMotionEffect * nonnull)effect

    Parameters

    effect

    The motion effect.

    Discussion

    The system animates the transition to the motion effect's values using the present UIView animation context. The motion effect’s keyPath/value pairs are applied to the view’s presentation layer.

    Availability

    Available in iOS 7.0 and later.

  • The array of motion effects for the view.

    Declaration

    Swift

    var motionEffects: [UIMotionEffect]

    Objective-C

    @property(copy, nonatomic) NSArray <__kindof UIMotionEffect *> *motionEffects

    Availability

    Available in iOS 7.0 and later.

  • Stops applying a motion effect to the view.

    Declaration

    Swift

    func removeMotionEffect(_ effect: UIMotionEffect)

    Objective-C

    - (void)removeMotionEffect:(UIMotionEffect * nonnull)effect

    Parameters

    effect

    The motion effect.

    Discussion

    Any affected presentation values animate to their post-removal values using the present UIView animation context.

    Availability

    Available in iOS 7.0 and later.

  • The identifier that determines whether the view supports state restoration.

    Declaration

    Swift

    var restorationIdentifier: String?

    Objective-C

    @property(nonatomic, copy) NSString *restorationIdentifier

    Discussion

    This property indicates whether state information in the view should be preserved; it is also used to identify the view during the restoration process. The value of this property is nil by default, which indicates that the view’s state does not need to be saved. Assigning a string object to the property lets the owning view controller know that the view has relevant state information to save.

    Assign a value to this property only if you are implementing a custom view that implements the encodeRestorableStateWithCoder: and decodeRestorableStateWithCoder: methods for saving and restoring state. You use those methods to write any view-specific state information and subsequently use that data to restore the view to its previous configuration.

    Availability

    Available in iOS 6.0 and later.

  • Encodes state-related information for the view.

    Declaration

    Swift

    func encodeRestorableStateWithCoder(_ coder: NSCoder)

    Objective-C

    - (void)encodeRestorableStateWithCoder:(NSCoder * nonnull)coder

    Parameters

    coder

    The coder object to use to encode the state of the view.

    Discussion

    If your app supports state preservation, you can override this method for any views that have state information that should be saved between launches of your app. You should save only the data required to return the view to its current configuration. Do not save the view object itself and do not save any data that could be determined by other means at launch time.

    Few views should need to save state information. Most views should just be configured using the data from their view controller. However, this method is available for those views that have user-configurable state that would be otherwise lost between app launches.

    Your implementation of this method can encode other restorable view and view controller objects that it needs to reference. Encoding a restorable view or view controller writes that object’s restoration identifier to the coder. (That identifier is used during the decode process to locate the new version of the object.) If the view or view controller defines its own own version of this method, that method is also called at some point so that the object can encode its own state.

    Apart from views and view controllers, other objects follow the normal serialization process and must adopt the NSCoding protocol before they can be encoded. Encoding such objects embeds the object’s contents in the archive directly. During the decode process, a new object is created and initialized with the data from the archive.

    It is recommended that you call super at some point during your implementation to give parent classes an opportunity to save their state information.

    Availability

    Available in iOS 6.0 and later.

  • Decodes and restores state-related information for the view.

    Declaration

    Swift

    func decodeRestorableStateWithCoder(_ coder: NSCoder)

    Objective-C

    - (void)decodeRestorableStateWithCoder:(NSCoder * nonnull)coder

    Parameters

    coder

    The coder object to use to decode the state of the view.

    Discussion

    If your app supports state restoration, you should override this method for any views for which you also overrode the encodeRestorableStateWithCoder: method. Your implementation of this method should use any saved state information to restore the view to its previous configuration. If your encodeRestorableStateWithCoder: method called super, this method should similarly call super at some point in its implementation.

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func snapshotViewAfterScreenUpdates(_ afterUpdates: Bool) -> UIView

    Objective-C

    - (UIView * nonnull)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates

    Parameters

    afterUpdates

    A Boolean value that specifies whether the snapshot should be taken after recent changes have been incorporated. Pass the value NOfalse to capture the screen in its current state, which might not include recent changes.

    Return Value

    A new view object based on a snapshot of the current view’s rendered contents.

    Discussion

    This method very efficiently captures the current rendered appearance of a view and uses it to build a new snapshot view. You can use the returned view as a visual stand-in for the current view in your app. For example, you might use a snapshot view for animations where updating a large view hierarchy might be expensive. Because the content is captured from the already rendered content, this method reflects the current visual appearance of the view and is not updated to reflect animations that are scheduled or in progress. However, calling this method is faster than trying to render the contents of the current view into a bitmap image yourself.

    Because the returned snapshot is a view object, you can modify it and its layer object as needed. However, you cannot change the contents property of the snapshot view’s layer; attempts to do so fail silently. If the current view is not yet rendered, perhaps because it is not yet onscreen, the snapshot view has no visible content.

    You can call this method on a previously generated snapshot to obtain a new snapshot. For example, you could do so after you change properties of a previous snapshot (such as its alpha value) and want a new snapshot that includes those changes.

    If you want to apply a graphical effect, such as blur, to a snapshot, use the drawViewHierarchyInRect:afterScreenUpdates: method instead.

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    func resizableSnapshotViewFromRect(_ rect: CGRect, afterScreenUpdates afterUpdates: Bool, withCapInsets capInsets: UIEdgeInsets) -> UIView

    Objective-C

    - (UIView * nonnull)resizableSnapshotViewFromRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates withCapInsets:(UIEdgeInsets)capInsets

    Parameters

    rect

    The portion of the view that you want to capture. The rectangle must be in the bounds coordinate space of the current view.

    afterUpdates

    A Boolean value that specifies whether the snapshot should be taken after recent changes have been incorporated. Pass the value NOfalse if you want to capture the screen in its current state, which might not include recent changes.

    capInsets

    The edge insets that define the stretchable portion of the returned view’s content. You can specify UIEdgeInsetsZero if you do not want the contents of the returned view to have a stretchable area.

    Return Value

    A new view object containing a snapshot of the current view’s rendered contents.

    Discussion

    This method very efficiently captures the current rendered appearance of a view and uses it to build a new snapshot view with stretchable insets. You can use the returned view as a visual stand-in for the current view in your app. For example, you might use a snapshot view for animations where updating a large view hierarchy might be expensive. Because the content is captured from the already rendered content, this method reflects the current visual appearance of the view and is not updated to reflect animations that are scheduled or in progress. However, calling this method is faster than trying to render the contents of the current view into a bitmap image yourself.

    Because the returned snapshot is a view object, you can modify it and its layer object as needed. However, you cannot change the contents property of the snapshot view’s layer; attempts to do so fail silently. If the current view is not yet rendered, perhaps because it is not yet onscreen, the snapshot view has no visible content.

    You can call this method on a previously generated snapshot to obtain a new snapshot. For example, you could do so after you change properties of a previous snapshot (such as its alpha value) and want a new snapshot that includes those changes.

    If you want to apply a graphical effect, such as blur, to a snapshot, use the drawViewHierarchyInRect:afterScreenUpdates: method instead.

    If you specify nonzero edge insets in the capInsets parameter, those values determine the returned snapshot’s stretchable content area.

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    func drawViewHierarchyInRect(_ rect: CGRect, afterScreenUpdates afterUpdates: Bool) -> Bool

    Objective-C

    - (BOOL)drawViewHierarchyInRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates

    Parameters

    rect

    A rectangle specified in the local coordinate system (bounds) of the view.

    afterUpdates

    A Boolean value that indicates whether the snapshot should be rendered after recent changes have been incorporated. Specify the value NOfalse if you want to render a snapshot in the view hierarchy’s current state, which might not include recent changes.

    Return Value

    Returns YEStrue if the snapshot is complete, or NOfalse if the snapshot is missing image data for any view in the hierarchy.

    Discussion

    Use this method when you want to apply a graphical effect, such as a blur, to a view snapshot. This method is not as fast as the snapshotViewAfterScreenUpdates: method.

    Availability

    Available in iOS 7.0 and later.

  • tag tag Property

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

    Declaration

    Swift

    var tag: Int

    Objective-C

    @property(nonatomic) NSInteger tag

    Discussion

    The default value is 0. You can set the value of this tag and use that value to identify the view later.

    Availability

    Available in iOS 2.0 and later.

  • Returns the view whose tag matches the specified value.

    Declaration

    Swift

    func viewWithTag(_ tag: Int) -> UIView?

    Objective-C

    - (UIView * nullable)viewWithTag:(NSInteger)tag

    Parameters

    tag

    The tag value to search for.

    Return Value

    The view in the receiver’s hierarchy whose tag property matches the value in the tag parameter.

    Discussion

    This method searches the current view and all of its subviews for the specified view.

    Availability

    Available in iOS 2.0 and later.

    See Also

    tag

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

    Declaration

    Swift

    func convertPoint(_ point: CGPoint, toView view: UIView?) -> CGPoint

    Objective-C

    - (CGPoint)convertPoint:(CGPoint)point toView:(UIView * nullable)view

    Parameters

    point

    A point specified in the local coordinate system (bounds) of the receiver.

    view

    The view into whose coordinate system point is to be converted. If view is nil, this method instead converts to window base coordinates. Otherwise, both view and the receiver must belong to the same UIWindow object.

    Return Value

    The point converted to the coordinate system of view.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func convertPoint(_ point: CGPoint, fromView view: UIView?) -> CGPoint

    Objective-C

    - (CGPoint)convertPoint:(CGPoint)point fromView:(UIView * nullable)view

    Parameters

    point

    A point specified in the local coordinate system (bounds) of view.

    view

    The view with point in its coordinate system. If view is nil, this method instead converts from window base coordinates. Otherwise, both view and the receiver must belong to the same UIWindow object.

    Return Value

    The point converted to the local coordinate system (bounds) of the receiver.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func convertRect(_ rect: CGRect, toView view: UIView?) -> CGRect

    Objective-C

    - (CGRect)convertRect:(CGRect)rect toView:(UIView * nullable)view

    Parameters

    rect

    A rectangle specified in the local coordinate system (bounds) of the receiver.

    view

    The view that is the target of the conversion operation. If view is nil, this method instead converts to window base coordinates. Otherwise, both view and the receiver must belong to the same UIWindow object.

    Return Value

    The converted rectangle.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func convertRect(_ rect: CGRect, fromView view: UIView?) -> CGRect

    Objective-C

    - (CGRect)convertRect:(CGRect)rect fromView:(UIView * nullable)view

    Parameters

    rect

    A rectangle specified in the local coordinate system (bounds) of view.

    view

    The view with rect in its coordinate system. If view is nil, this method instead converts from window base coordinates. Otherwise, both view and the receiver must belong to the same UIWindow object.

    Return Value

    The converted rectangle.

    Availability

    Available in iOS 2.0 and later.

  • Returns the farthest descendant of the receiver in the view hierarchy (including itself) that contains a specified point.

    Declaration

    Swift

    func hitTest(_ point: CGPoint, withEvent event: UIEvent?) -> UIView?

    Objective-C

    - (UIView * nullable)hitTest:(CGPoint)point withEvent:(UIEvent * nullable)event

    Parameters

    point

    A point specified in the receiver’s local coordinate system (bounds).

    event

    The event that warranted a call to this method. If you are calling this method from outside your event-handling code, you may specify nil.

    Return Value

    The view object that is the farthest descendent the current view and contains point. Returns nil if the point lies completely outside the receiver’s view hierarchy.

    Discussion

    This method traverses the view hierarchy by calling the pointInside:withEvent: method of each subview to determine which subview should receive a touch event. If pointInside:withEvent: returns YEStrue, then the subview’s hierarchy is similarly traversed until the frontmost view containing the specified point is found. If a view does not contain the point, its branch of the view hierarchy is ignored. You rarely need to call this method yourself, but you might override it to hide touch events from subviews.

    This method ignores view objects that are hidden, that have disabled user interactions, or have an alpha level less than 0.01. This method does not take the view’s content into account when determining a hit. Thus, a view can still be returned even if the specified point is in a transparent portion of that view’s content.

    Points that lie outside the receiver’s bounds are never reported as hits, even if they actually lie within one of the receiver’s subviews. This can occur if the current view’s clipsToBounds property is set to NOfalse and the affected subview extends beyond the view’s bounds.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func pointInside(_ point: CGPoint, withEvent event: UIEvent?) -> Bool

    Objective-C

    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent * nullable)event

    Parameters

    point

    A point that is in the receiver’s local coordinate system (bounds).

    event

    The event that warranted a call to this method. If you are calling this method from outside your event-handling code, you may specify nil.

    Return Value

    YEStrue if point is inside the receiver’s bounds; otherwise, NOfalse.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func endEditing(_ force: Bool) -> Bool

    Objective-C

    - (BOOL)endEditing:(BOOL)force

    Parameters

    force

    Specify YEStrue to force the first responder to resign, regardless of whether it wants to do so.

    Return Value

    YEStrue if the view resigned the first responder status or NOfalse if it did not.

    Discussion

    This method looks at the current view and its subview hierarchy for the text field that is currently the first responder. If it finds one, it asks that text field to resign as first responder. If the force parameter is set to YEStrue, the text field is never even asked; it is forced to resign.

    Availability

    Available in iOS 2.0 and later.

  • Tells the view that a subview was added.

    Declaration

    Swift

    func didAddSubview(_ subview: UIView)

    Objective-C

    - (void)didAddSubview:(UIView * nonnull)subview

    Parameters

    subview

    The view that was added as a subview.

    Discussion

    The default implementation of this method does nothing. Subclasses can override it to perform additional actions when subviews are added. This method is called in response to adding a subview using any of the relevant view methods.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func willRemoveSubview(_ subview: UIView)

    Objective-C

    - (void)willRemoveSubview:(UIView * nonnull)subview

    Parameters

    subview

    The subview that will be removed.

    Discussion

    The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever subviews are removed. This method is called when the subview’s superview changes or when the subview is removed from the view hierarchy completely.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func willMoveToSuperview(_ newSuperview: UIView?)

    Objective-C

    - (void)willMoveToSuperview:(UIView * nullable)newSuperview

    Parameters

    newSuperview

    A view object that will be the new superview of the receiver. This object may be nil.

    Discussion

    The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the superview changes.

    Availability

    Available in iOS 2.0 and later.

  • Tells the view that its superview changed.

    Declaration

    Swift

    func didMoveToSuperview()

    Objective-C

    - (void)didMoveToSuperview

    Discussion

    The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the superview changes.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func willMoveToWindow(_ newWindow: UIWindow?)

    Objective-C

    - (void)willMoveToWindow:(UIWindow * nullable)newWindow

    Parameters

    newWindow

    The window object that will be at the root of the receiver's new view hierarchy. This parameter may be nil.

    Discussion

    The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the window changes.

    Availability

    Available in iOS 2.0 and later.

  • Tells the view that its window object changed.

    Declaration

    Swift

    func didMoveToWindow()

    Objective-C

    - (void)didMoveToWindow

    Discussion

    The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the window changes.

    The window property may be nil by the time that this method is called, indicating that the receiver does not currently reside in any window. This occurs when the receiver has just been removed from its superview or when the receiver has just been added to a superview that is not attached to a window. Overrides of this method may choose to ignore such cases if they are not of interest.

    Availability

    Available in iOS 2.0 and later.

Data Types

  • Options for animating views using block objects.

    Declaration

    Swift

    struct UIViewAnimationOptions : OptionSetType { init(rawValue rawValue: UInt) static var LayoutSubviews: UIViewAnimationOptions { get } static var AllowUserInteraction: UIViewAnimationOptions { get } static var BeginFromCurrentState: UIViewAnimationOptions { get } static var Repeat: UIViewAnimationOptions { get } static var Autoreverse: UIViewAnimationOptions { get } static var OverrideInheritedDuration: UIViewAnimationOptions { get } static var OverrideInheritedCurve: UIViewAnimationOptions { get } static var AllowAnimatedContent: UIViewAnimationOptions { get } static var ShowHideTransitionViews: UIViewAnimationOptions { get } static var OverrideInheritedOptions: UIViewAnimationOptions { get } static var CurveEaseInOut: UIViewAnimationOptions { get } static var CurveEaseIn: UIViewAnimationOptions { get } static var CurveEaseOut: UIViewAnimationOptions { get } static var CurveLinear: UIViewAnimationOptions { get } static var TransitionNone: UIViewAnimationOptions { get } static var TransitionFlipFromLeft: UIViewAnimationOptions { get } static var TransitionFlipFromRight: UIViewAnimationOptions { get } static var TransitionCurlUp: UIViewAnimationOptions { get } static var TransitionCurlDown: UIViewAnimationOptions { get } static var TransitionCrossDissolve: UIViewAnimationOptions { get } static var TransitionFlipFromTop: UIViewAnimationOptions { get } static var TransitionFlipFromBottom: UIViewAnimationOptions { get } }

    Objective-C

    enum { UIViewAnimationOptionLayoutSubviews = 1 << 0, UIViewAnimationOptionAllowUserInteraction = 1 << 1, UIViewAnimationOptionBeginFromCurrentState = 1 << 2, UIViewAnimationOptionRepeat = 1 << 3, UIViewAnimationOptionAutoreverse = 1 << 4, UIViewAnimationOptionOverrideInheritedDuration = 1 << 5, UIViewAnimationOptionOverrideInheritedCurve = 1 << 6, UIViewAnimationOptionAllowAnimatedContent = 1 << 7, UIViewAnimationOptionShowHideTransitionViews = 1 << 8, UIViewAnimationOptionOverrideInheritedOptions = 1 << 9, UIViewAnimationOptionCurveEaseInOut = 0 << 16, UIViewAnimationOptionCurveEaseIn = 1 << 16, UIViewAnimationOptionCurveEaseOut = 2 << 16, UIViewAnimationOptionCurveLinear = 3 << 16, UIViewAnimationOptionTransitionNone = 0 << 20, UIViewAnimationOptionTransitionFlipFromLeft = 1 << 20, UIViewAnimationOptionTransitionFlipFromRight = 2 << 20, UIViewAnimationOptionTransitionCurlUp = 3 << 20, UIViewAnimationOptionTransitionCurlDown = 4 << 20, UIViewAnimationOptionTransitionCrossDissolve = 5 << 20, UIViewAnimationOptionTransitionFlipFromTop = 6 << 20, UIViewAnimationOptionTransitionFlipFromBottom = 7 << 20, }; typedef NSUInteger UIViewAnimationOptions;

    Constants

    • LayoutSubviews

      UIViewAnimationOptionLayoutSubviews

      Lay out subviews at commit time so that they are animated along with their parent.

      Available in iOS 4.0 and later.

    • AllowUserInteraction

      UIViewAnimationOptionAllowUserInteraction

      Allow the user to interact with views while they are being animated.

      Available in iOS 4.0 and later.

    • BeginFromCurrentState

      UIViewAnimationOptionBeginFromCurrentState

      Start the animation from the current setting associated with an already in-flight animation. If this key is not present, any in-flight animations are allowed to finish before the new animation is started. If another animation is not in flight, this key has no effect.

      Available in iOS 4.0 and later.

    • Repeat

      UIViewAnimationOptionRepeat

      Repeat the animation indefinitely.

      Available in iOS 4.0 and later.

    • Autoreverse

      UIViewAnimationOptionAutoreverse

      Run the animation backwards and forwards. Must be combined with the UIViewAnimationOptionRepeat option.

      Available in iOS 4.0 and later.

    • OverrideInheritedDuration

      UIViewAnimationOptionOverrideInheritedDuration

      Force the animation to use the original duration value specified when the animation was submitted. If this key is not present, the animation inherits the remaining duration of the in-flight animation, if any.

      Available in iOS 4.0 and later.

    • OverrideInheritedCurve

      UIViewAnimationOptionOverrideInheritedCurve

      Force the animation to use the original curve value specified when the animation was submitted. If this key is not present, the animation inherits the curve of the in-flight animation, if any.

      Available in iOS 4.0 and later.

    • AllowAnimatedContent

      UIViewAnimationOptionAllowAnimatedContent

      Animate the views by changing the property values dynamically and redrawing the view. If this key is not present, the views are animated using a snapshot image.

      Available in iOS 4.0 and later.

    • ShowHideTransitionViews

      UIViewAnimationOptionShowHideTransitionViews

      When present, this key causes views to be hidden or shown (instead of removed or added) when performing a view transition. Both views must already be present in the parent view’s hierarchy when using this key. If this key is not present, the to-view in a transition is added to, and the from-view is removed from, the parent view’s list of subviews.

      Available in iOS 4.0 and later.

    • OverrideInheritedOptions

      UIViewAnimationOptionOverrideInheritedOptions

      The option to not inherit the animation type or any options.

      Available in iOS 4.0 and later.

    • CurveEaseInOut

      UIViewAnimationOptionCurveEaseInOut

      An ease-in ease-out curve causes the animation to begin slowly, accelerate through the middle of its duration, and then slow again before completing.

      Available in iOS 4.0 and later.

    • CurveEaseIn

      UIViewAnimationOptionCurveEaseIn

      An ease-in curve causes the animation to begin slowly, and then speed up as it progresses.

      Available in iOS 4.0 and later.

    • CurveEaseOut

      UIViewAnimationOptionCurveEaseOut

      An ease-out curve causes the animation to begin quickly, and then slow as it completes.

      Available in iOS 4.0 and later.

    • CurveLinear

      UIViewAnimationOptionCurveLinear

      A linear animation curve causes an animation to occur evenly over its duration.

      Available in iOS 4.0 and later.

    • TransitionNone

      UIViewAnimationOptionTransitionNone

      No transition is specified.

      Available in iOS 4.0 and later.

    • TransitionFlipFromLeft

      UIViewAnimationOptionTransitionFlipFromLeft

      A transition that flips a view around its vertical axis from left to right. The left side of the view moves toward the front and right side toward the back.

      Available in iOS 4.0 and later.

    • TransitionFlipFromRight

      UIViewAnimationOptionTransitionFlipFromRight

      A transition that flips a view around its vertical axis from right to left. The right side of the view moves toward the front and left side toward the back.

      Available in iOS 4.0 and later.

    • TransitionCurlUp

      UIViewAnimationOptionTransitionCurlUp

      A transition that curls a view up from the bottom.

      Available in iOS 4.0 and later.

    • TransitionCurlDown

      UIViewAnimationOptionTransitionCurlDown

      A transition that curls a view down from the top.

      Available in iOS 4.0 and later.

    • TransitionCrossDissolve

      UIViewAnimationOptionTransitionCrossDissolve

      A transition that dissolves from one view to the next.

      Available in iOS 4.0 and later.

    • TransitionFlipFromTop

      UIViewAnimationOptionTransitionFlipFromTop

      A transition that flips a view around its horizontal axis from top to bottom. The top side of the view moves toward the front and the bottom side toward the back.

      Available in iOS 4.0 and later.

    • TransitionFlipFromBottom

      UIViewAnimationOptionTransitionFlipFromBottom

      A transition that flips a view around its horizontal axis from bottom to top. The bottom side of the view moves toward the front and the top side toward the back.

      Available in iOS 4.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

  • Specifies the supported animation curves.

    Declaration

    Swift

    enum UIViewAnimationCurve : Int { case EaseInOut case EaseIn case EaseOut case Linear }

    Objective-C

    typedef enum { UIViewAnimationCurveEaseInOut, UIViewAnimationCurveEaseIn, UIViewAnimationCurveEaseOut, UIViewAnimationCurveLinear } UIViewAnimationCurve;

    Constants

    • EaseInOut

      UIViewAnimationCurveEaseInOut

      An ease-in ease-out curve causes the animation to begin slowly, accelerate through the middle of its duration, and then slow again before completing. This is the default curve for most animations.

      Available in iOS 2.0 and later.

    • EaseIn

      UIViewAnimationCurveEaseIn

      An ease-in curve causes the animation to begin slowly, and then speed up as it progresses.

      Available in iOS 2.0 and later.

    • EaseOut

      UIViewAnimationCurveEaseOut

      An ease-out curve causes the animation to begin quickly, and then slow down as it completes.

      Available in iOS 2.0 and later.

    • Linear

      UIViewAnimationCurveLinear

      A linear animation curve causes an animation to occur evenly over its duration.

      Available in iOS 2.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    enum UIViewContentMode : Int { case ScaleToFill case ScaleAspectFit case ScaleAspectFill case Redraw case Center case Top case Bottom case Left case Right case TopLeft case TopRight case BottomLeft case BottomRight }

    Objective-C

    typedef enum { UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleAspectFill, UIViewContentModeRedraw, UIViewContentModeCenter, UIViewContentModeTop, UIViewContentModeBottom, UIViewContentModeLeft, UIViewContentModeRight, UIViewContentModeTopLeft, UIViewContentModeTopRight, UIViewContentModeBottomLeft, UIViewContentModeBottomRight, } UIViewContentMode;

    Constants

    • ScaleToFill

      UIViewContentModeScaleToFill

      The option to scale the content to fit the size of itself by changing the aspect ratio of the content if necessary.

      Available in iOS 2.0 and later.

    • ScaleAspectFit

      UIViewContentModeScaleAspectFit

      The option to scale the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the view’s bounds is transparent.

      Available in iOS 2.0 and later.

    • ScaleAspectFill

      UIViewContentModeScaleAspectFill

      The option to scale the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.

      Available in iOS 2.0 and later.

    • Redraw

      UIViewContentModeRedraw

      The option to redisplay the view when the bounds change by invoking the setNeedsDisplay method.

      Available in iOS 2.0 and later.

    • Center

      UIViewContentModeCenter

      The option to center the content in the view’s bounds, keeping the proportions the same.

      Available in iOS 2.0 and later.

    • Top

      UIViewContentModeTop

      The option to center the content aligned at the top in the view’s bounds.

      Available in iOS 2.0 and later.

    • Bottom

      UIViewContentModeBottom

      The option to center the content aligned at the bottom in the view’s bounds.

      Available in iOS 2.0 and later.

    • Left

      UIViewContentModeLeft

      The option to align the content on the left of the view.

      Available in iOS 2.0 and later.

    • Right

      UIViewContentModeRight

      The option to align the content on the right of the view.

      Available in iOS 2.0 and later.

    • TopLeft

      UIViewContentModeTopLeft

      The option to align the content in the top-left corner of the view.

      Available in iOS 2.0 and later.

    • TopRight

      UIViewContentModeTopRight

      The option to align the content in the top-right corner of the view.

      Available in iOS 2.0 and later.

    • BottomLeft

      UIViewContentModeBottomLeft

      The option to align the content in the bottom-left corner of the view.

      Available in iOS 2.0 and later.

    • BottomRight

      UIViewContentModeBottomRight

      The option to align the content in the bottom-right corner of the view.

      Available in iOS 2.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The tint adjustment mode for the view.

    Declaration

    Swift

    enum UIViewTintAdjustmentMode : Int { case Automatic case Normal case Dimmed }

    Objective-C

    typedef enum { UIViewTintAdjustmentModeAutomatic, UIViewTintAdjustmentModeNormal, UIViewTintAdjustmentModeDimmed, } UIViewTintAdjustmentMode;

    Constants

    • Automatic

      UIViewTintAdjustmentModeAutomatic

      The tint adjustment mode of the view is the same as its superview's tint adjustment mode (or UIViewTintAdjustmentModeNormal if the view has no superview).

      Available in iOS 7.0 and later.

    • Normal

      UIViewTintAdjustmentModeNormal

      The view's tintColor property returns the completely unmodified tint color of the view.

      Available in iOS 7.0 and later.

    • Dimmed

      UIViewTintAdjustmentModeDimmed

      The view's tintColor property returns a desaturated, dimmed version of the view's original tint color.

      Available in iOS 7.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    enum UISystemAnimation : UInt { case Delete }

    Objective-C

    typedef enum{ UISystemAnimationDelete, } UISystemAnimation;

    Constants

    • Delete

      UISystemAnimationDelete

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

      Available in iOS 7.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Options for automatic view resizing.

    Declaration

    Swift

    struct UIViewAutoresizing : OptionSetType { init(rawValue rawValue: UInt) static var None: UIViewAutoresizing { get } static var FlexibleLeftMargin: UIViewAutoresizing { get } static var FlexibleWidth: UIViewAutoresizing { get } static var FlexibleRightMargin: UIViewAutoresizing { get } static var FlexibleTopMargin: UIViewAutoresizing { get } static var FlexibleHeight: UIViewAutoresizing { get } static var FlexibleBottomMargin: UIViewAutoresizing { get } }

    Objective-C

    enum { UIViewAutoresizingNone = 0, UIViewAutoresizingFlexibleLeftMargin = 1 << 0, UIViewAutoresizingFlexibleWidth = 1 << 1, UIViewAutoresizingFlexibleRightMargin = 1 << 2, UIViewAutoresizingFlexibleTopMargin = 1 << 3, UIViewAutoresizingFlexibleHeight = 1 << 4, UIViewAutoresizingFlexibleBottomMargin = 1 << 5 }; typedef NSUInteger UIViewAutoresizing;

    Constants

    • None

      UIViewAutoresizingNone

      The option for indicating that the view does not resize.

      Available in iOS 2.0 and later.

    • FlexibleLeftMargin

      UIViewAutoresizingFlexibleLeftMargin

      Resizing performed by expanding or shrinking a view in the direction of the left margin.

      Available in iOS 2.0 and later.

    • FlexibleWidth

      UIViewAutoresizingFlexibleWidth

      Resizing performed by expanding or shrinking a view’s width.

      Available in iOS 2.0 and later.

    • FlexibleRightMargin

      UIViewAutoresizingFlexibleRightMargin

      Resizing performed by expanding or shrinking a view in the direction of the right margin.

      Available in iOS 2.0 and later.

    • FlexibleTopMargin

      UIViewAutoresizingFlexibleTopMargin

      Resizing performed by expanding or shrinking a view in the direction of the top margin.

      Available in iOS 2.0 and later.

    • FlexibleHeight

      UIViewAutoresizingFlexibleHeight

      Resizing performed by expanding or shrinking a view's height.

      Available in iOS 2.0 and later.

    • FlexibleBottomMargin

      UIViewAutoresizingFlexibleBottomMargin

      Resizing performed by expanding or shrinking a view in the direction of the bottom margin.

      Available in iOS 2.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Animation transition options for use in an animation block object.

    Declaration

    Swift

    enum UIViewAnimationTransition : Int { case None case FlipFromLeft case FlipFromRight case CurlUp case CurlDown }

    Objective-C

    typedef enum { UIViewAnimationTransitionNone, UIViewAnimationTransitionFlipFromLeft, UIViewAnimationTransitionFlipFromRight, UIViewAnimationTransitionCurlUp, UIViewAnimationTransitionCurlDown, } UIViewAnimationTransition;

    Constants

    • None

      UIViewAnimationTransitionNone

      The option for indicating that no transition is specified.

      Available in iOS 2.0 and later.

    • FlipFromLeft

      UIViewAnimationTransitionFlipFromLeft

      A transition that flips a view around a vertical axis from left to right. The left side of the view moves towards the front and right side towards the back.

      Available in iOS 2.0 and later.

    • FlipFromRight

      UIViewAnimationTransitionFlipFromRight

      A transition that flips a view around a vertical axis from right to left. The right side of the view moves towards the front and left side towards the back.

      Available in iOS 2.0 and later.

    • CurlUp

      UIViewAnimationTransitionCurlUp

      A transition that curls a view up from the bottom.

      Available in iOS 2.0 and later.

    • CurlDown

      UIViewAnimationTransitionCurlDown

      A transition that curls a view down from the top.

      Available in iOS 2.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Key frame animation options used with the animateKeyframesWithDuration:delay:options:animations:completion: method.

    Declaration

    Swift

    struct UIViewKeyframeAnimationOptions : OptionSetType { init(rawValue rawValue: UInt) static var LayoutSubviews: UIViewKeyframeAnimationOptions { get } static var AllowUserInteraction: UIViewKeyframeAnimationOptions { get } static var BeginFromCurrentState: UIViewKeyframeAnimationOptions { get } static var Repeat: UIViewKeyframeAnimationOptions { get } static var Autoreverse: UIViewKeyframeAnimationOptions { get } static var OverrideInheritedDuration: UIViewKeyframeAnimationOptions { get } static var OverrideInheritedOptions: UIViewKeyframeAnimationOptions { get } static var CalculationModeLinear: UIViewKeyframeAnimationOptions { get } static var CalculationModeDiscrete: UIViewKeyframeAnimationOptions { get } static var CalculationModePaced: UIViewKeyframeAnimationOptions { get } static var CalculationModeCubic: UIViewKeyframeAnimationOptions { get } static var CalculationModeCubicPaced: UIViewKeyframeAnimationOptions { get } }

    Objective-C

    typedef enum { UIViewKeyframeAnimationOptionLayoutSubviews = UIViewAnimationOptionLayoutSubviews, UIViewKeyframeAnimationOptionAllowUserInteraction = UIViewAnimationOptionAllowUserInteraction, UIViewKeyframeAnimationOptionBeginFromCurrentState = UIViewAnimationOptionBeginFromCurrentState, UIViewKeyframeAnimationOptionRepeat = UIViewAnimationOptionRepeat, UIViewKeyframeAnimationOptionAutoreverse = UIViewAnimationOptionAutoreverse, UIViewKeyframeAnimationOptionOverrideInheritedDuration = UIViewAnimationOptionOverrideInheritedDuration, UIViewKeyframeAnimationOptionOverrideInheritedOptions = UIViewAnimationOptionOverrideInheritedOptions, UIViewKeyframeAnimationOptionCalculationModeLinear = 0 << 9, UIViewKeyframeAnimationOptionCalculationModeDiscrete = 1 << 9, UIViewKeyframeAnimationOptionCalculationModePaced = 2 << 9, UIViewKeyframeAnimationOptionCalculationModeCubic = 3 << 9, UIViewKeyframeAnimationOptionCalculationModeCubicPaced = 4 << 9 } UIViewKeyframeAnimationOptions;

    Constants

    • LayoutSubviews

      UIViewKeyframeAnimationOptionLayoutSubviews

      The option to lay out subviews at commit time so that they are animated along with their parent.

      Available in iOS 7.0 and later.

    • AllowUserInteraction

      UIViewKeyframeAnimationOptionAllowUserInteraction

      The option that allows the user to interact with views while they are being animated.

      Available in iOS 7.0 and later.

    • BeginFromCurrentState

      UIViewKeyframeAnimationOptionBeginFromCurrentState

      The option to start an animation from the current setting associated with an already in-flight animation. If this option is not present, any in-flight animations are allowed to finish before the new animation is started. If another animation is not in flight, this option has no effect.

      Available in iOS 7.0 and later.

    • Repeat

      UIViewKeyframeAnimationOptionRepeat

      The option to repeat an animation indefinitely.

      Available in iOS 7.0 and later.

    • Autoreverse

      UIViewKeyframeAnimationOptionAutoreverse

      The option to run an animation backwards and forwards. Must be combined with the UIViewKeyframeAnimationOptionRepeat option.

      Available in iOS 7.0 and later.

    • OverrideInheritedDuration

      UIViewKeyframeAnimationOptionOverrideInheritedDuration

      The option to force an animation to use the original duration value specified when the animation was submitted. If this option is not present, the animation inherits the remaining duration of the in-flight animation, if any.

      Available in iOS 7.0 and later.

    • OverrideInheritedOptions

      UIViewKeyframeAnimationOptionOverrideInheritedOptions

      The option to not inherit the animation type or any options.

      Available in iOS 7.0 and later.

    • CalculationModeLinear

      UIViewKeyframeAnimationOptionCalculationModeLinear

      The option to use a simple linear calculation when interpolating between keyframe values.

      Available in iOS 7.0 and later.

    • CalculationModeDiscrete

      UIViewKeyframeAnimationOptionCalculationModeDiscrete

      The option to not interpolate between keyframe values, but rather to jump directly to each new keyframe value.

      Available in iOS 7.0 and later.

    • CalculationModePaced

      UIViewKeyframeAnimationOptionCalculationModePaced

      The option to compute intermediate keyframe values using a simple pacing algorithm. This option results in an evenly paced animation.

      Available in iOS 7.0 and later.

    • CalculationModeCubic

      UIViewKeyframeAnimationOptionCalculationModeCubic

      The option to compute intermediate frames using a default Catmull-Rom spline that passes through the keyframe values. You cannot adjust the parameters of this algorithm.

      Available in iOS 7.0 and later.

    • CalculationModeCubicPaced

      UIViewKeyframeAnimationOptionCalculationModeCubicPaced

      The option to compute intermediate frames using the cubic scheme while ignoring the timing properties of the animation. Instead, timing parameters are calculated implicitly to give the animation a constant velocity.

      Available in iOS 7.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    enum UILayoutConstraintAxis : Int { case Horizontal case Vertical }

    Objective-C

    enum { UILayoutConstraintAxisHorizontal = 0, UILayoutConstraintAxisVertical = 1 }; typedef NSInteger UILayoutConstraintAxis;

    Constants

    • Horizontal

      UILayoutConstraintAxisHorizontal

      The constraint applied when laying out the horizontal relationship between objects.

      Available in iOS 6.0 and later.

    • Vertical

      UILayoutConstraintAxisVertical

      The constraint applied when laying out the vertical relationship between objects.

      Available in iOS 6.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • View fitting options used in the systemLayoutSizeFittingSize: method.

    Declaration

    Swift

    let UILayoutFittingCompressedSize: CGSize let UILayoutFittingExpandedSize: CGSize

    Objective-C

    const CGSize UILayoutFittingCompressedSize; const CGSize UILayoutFittingExpandedSize;

    Constants

    • UILayoutFittingCompressedSize

      UILayoutFittingCompressedSize

      The option to use the smallest possible size.

      Available in iOS 6.0 and later.

    • UILayoutFittingExpandedSize

      UILayoutFittingExpandedSize

      The option to use the largest possible size.

      Available in iOS 6.0 and later.

  • The option to indicate that a view has no intrinsic metric for a given numeric property.

    Declaration

    Swift

    let UIViewNoIntrinsicMetric: CGFloat

    Objective-C

    const CGFloat UIViewNoIntrinsicMetric;

    Constants

    • UIViewNoIntrinsicMetric

      UIViewNoIntrinsicMetric

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

      Available in iOS 6.0 and later.

  • 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.

    Declaration

    Swift

    enum UISemanticContentAttribute : Int { case Unspecified case Playback case Spatial case ForceLeftToRight case ForceRightToLeft }

    Objective-C

    typedef enum : NSInteger { UISemanticContentAttributeUnspecified = 0, UISemanticContentAttributePlayback, UISemanticContentAttributeSpatial, UISemanticContentAttributeForceLeftToRight, UISemanticContentAttributeForceRightToLeft } UISemanticContentAttribute;

    Constants

    • Unspecified

      UISemanticContentAttributeUnspecified

      The default value for views. The view is flipped when switching between left-to-right and right-to-left layouts.

      Available in iOS 9.0 and later.

    • Playback

      UISemanticContentAttributePlayback

      A view representing the playback controls, such as Play, Rewind, or Fast Forward buttons or playhead scrubbers. These views are not flipped when switching between left-to-right and right-to-left layouts.

      Available in iOS 9.0 and later.

    • Spatial

      UISemanticContentAttributeSpatial

      A view representing a directional control, for example a segment control for text alignment, or a D-pad control for a game. These views are not flipped when switching between left-to-right and right-to-left layouts.

      Available in iOS 9.0 and later.

    • ForceLeftToRight

      UISemanticContentAttributeForceLeftToRight

      A view that is always displayed using a left-to-right layout.

      Available in iOS 9.0 and later.

    • ForceRightToLeft

      UISemanticContentAttributeForceRightToLeft

      A view that is always displayed using a right-to-left layout.

      Available in iOS 9.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 9.0 and later.