| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iPhone OS 2.0 and later. |
| Declared in | UITextField.h UIView.h |
| Related sample code |
The UIView class is primarily an abstract superclass that provides concrete subclasses with a structure for drawing and handling events. You can also create instances of UIView to contain other views.
UIView objects are arranged within an UIWindow object, in a nested hierarchy of subviews. Parent objects in the view hierarchy are called superviews, and children are called subviews. A view object claims a rectangular region of its enclosing superview, is responsible for all drawing within that region, and is eligible to receive events occurring in it as well. Sibling views are able to overlap without any issues, allowing complex view placement.
The UIView class provides common methods you use to create all types of views and access their properties. For example, unless a subclass has its own designated initializer, you use the initWithFrame: method to create a view. The frame property specifies the origin and size of a view in superview coordinates. The origin of the coordinate system for all views is in the upper-left corner.
You can also use the center and bounds properties to set the position and size of a view. The center property specifies the view’s center point in superview’s coordinates. The bounds property specifies the origin in the view’s coordinates and its size (the view’s content may be larger than the bounds size). The frame property is actually computed based on the center and bounds property values. Therefore, you can set any of these three properties and they affect the values of the others.
It’s important to set the autoresizing properties of views so that when they are displayed or the orientation changes, the views are displayed correctly within the superview’s bounds. Use the autoresizesSubviews property, especially if you subclass UIView, to specify whether the view should automatically resize its subviews. Use the autoresizingMask property with the constants described in UIViewAutoresizing to specify how a view should automatically resize.
The UIView class provides a number of methods for managing the view hierarchy. Use the superview property to get the parent view and the subviews property to get the child views in the hierarchy. There are also a number of methods, listed in “Managing the View Hierarchy,” for adding, inserting, and removing subviews as well as arranging subviews in front of or in back of siblings.
When you subclass UIView to create a custom class that draws itself, implement the drawRect: method to draw the view within the specified region. This method is invoked the first time a view displays or when an event occurs that invalidates a part of the view’s frame requiring it to redraw its content.
Normal geometry changes do not require redrawing the view. Therefore, if you alter the appearance of a view and want to force it to redraw, send setNeedsDisplay or setNeedsDisplayInRect: to the view. You can also set the contentMode to UIViewContentModeRedraw to invoke the drawRect: method when the bounds change; otherwise, the view is scaled and clipped without redrawing the content.
Subclasses can also be containers for other views. In this case, just override the designated initializer, initWithFrame:, to create a view hierarchy. If you want to programmatically force the layout of subviews before drawing, send setNeedsLayout to the view. Then when layoutIfNeeded is invoked, the layoutSubviews method is invoked just before displaying. Subclasses should override layoutSubviews to perform any custom arrangement of subviews.
Some of the property changes to view objects can be animated—for example, setting the frame, bounds, center, and transform properties. If you change these properties in an animation block, the changes from the current state to the new state are animated. Invoke the beginAnimations:context: class method to begin an animation block, set the properties you want animated, and then invoke the commitAnimations class method to end an animation block. The animations are run in a separate thread and begin when the application returns to the run loop. Other animation class methods allow you to control the start time, duration, delay, and curve of the animations within the block.
Use the hitTest:withEvent: and pointInside:withEvent: methods if you are processing events and want to know where they occur. The UIView class inherits other event processing methods from UIResponder. For more information on how views handle events, read UIResponder Class Reference.
Read Window and Views in iPhone Application Programming Guide to learn how to use this class.
UIView instances may have a maximum height and width of 1024 x 1024. In iPhone OS 3.0 and later, views are no longer restricted to this maximum size but are still limited by the amount of memory they consume. Therefore, it is in your best interests to keep view sizes as small as possible. Regardless of which version of iPhone OS is running, you should consider using a CATiledLayer object if you need to create views larger than 1024 x 1024 in size. userInteractionEnabled property
superview property
subviews property
window property
– addSubview:
– bringSubviewToFront:
– sendSubviewToBack:
– removeFromSuperview
– insertSubview:atIndex:
– insertSubview:aboveSubview:
– insertSubview:belowSubview:
– exchangeSubviewAtIndex:withSubviewAtIndex:
– isDescendantOfView:
autoresizesSubviews property
autoresizingMask property
– sizeThatFits:
– sizeToFit
contentMode property
contentStretch property
tag property
– viewWithTag:
clipsToBounds property
backgroundColor property
alpha property
opaque property
clearsContextBeforeDrawing property
– drawRect:
– setNeedsDisplay
– setNeedsDisplayInRect:
+ layerClass
layer property
hidden property
+ beginAnimations:context:
+ commitAnimations
+ setAnimationStartDate:
+ setAnimationsEnabled:
+ setAnimationDelegate:
+ setAnimationWillStartSelector:
+ setAnimationDidStopSelector:
+ setAnimationDuration:
+ setAnimationDelay:
+ setAnimationCurve:
+ setAnimationRepeatCount:
+ setAnimationRepeatAutoreverses:
+ setAnimationBeginsFromCurrentState:
+ setAnimationTransition:forView:cache:
+ areAnimationsEnabled
– hitTest:withEvent:
– pointInside:withEvent:
multipleTouchEnabled property
exclusiveTouch property
– endEditing:
For more about Objective-C properties, see “Properties” in The Objective-C Programming Language.
The receiver’s alpha value.
@property(nonatomic) CGFloat alpha
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.
UIView.hA Boolean value that determines whether the receiver automatically resizes its subviews when its frame size changes.
@property(nonatomic) BOOL autoresizesSubviews
If YES, the receiver adjusts the size of its subviews when the bounds change. The default value is YES.
UIView.hAn integer bit mask that determines how the receiver resizes itself when its bounds change.
@property(nonatomic) UIViewAutoresizing autoresizingMask
This mask can be specified by combining, using the C bitwise OR operator, any of the options described in UIViewAutoresizing.
Where more than one option along an axis is set, the default behavior is to distribute the size difference as evenly as possible among the flexible portions. For example, if frame and autoresizingMask are set and the superview’s width has increased by 10.0 units, the receiver’s frame and right margin are each widened by 5.0 units. Subclasses of UIView can override the layoutSubviews method to explicitly adjust the position of subviews.
If the autoresizing mask is equal to UIViewAutoresizingNone, then the receiver doesn’t resize at all when its bounds changes. The default value is UIViewAutoresizingNone.
UIView.hThe receiver’s background color.
@property(nonatomic, copy) UIColor *backgroundColor
The default is nil.
UIView.hThe receiver’s bounds rectangle, which expresses its location and size in its own coordinate system.
@property(nonatomic) CGRect bounds
The bounds rectangle determines the origin and scale in the view’s coordinate system within its frame rectangle. Setting this property changes the value of the frame property 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.
The default bounds origin is (0,0) and the size is the same as the frame rectangle’s size.
UIView.hThe center of the frame.
@property(nonatomic) CGPoint center
The center is specified within the coordinate system of its superview. Setting this property changes the values of the frame properties accordingly.
Changing the frame rectangle automatically redisplay 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.
UIView.hA Boolean value that determines whether the receiver’s bounds should be automatically cleared before drawing.
@property(nonatomic) BOOL clearsContextBeforeDrawing
If YES, the current graphics context buffer in the drawRect: method is automatically cleared to transparent black before drawRect: is invoked. If NO, it’s the application’s responsibility to completely fill its content. Drawing performance can be improved if this property is NO—for example, when scrolling. The default value is YES.
UIView.hA Boolean value that determines whether subviews can be drawn outside the bounds of the receiver.
@property(nonatomic) BOOL clipsToBounds
YES if subviews should be clipped to the bounds of the receiver; otherwise, NO. The default value is NO.
UIView.hA flag used to determine how a view lays out its content when its bounds rectangle changes.
@property(nonatomic) UIViewContentMode contentMode
Set to a value described in UIViewContentMode. The default value is UIViewContentModeScaleToFill.
UIView.hThe rectangle that defines the stretchable and nonstretchable regions of a view.
@property(nonatomic) CGRect contentStretch
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. This technique applies the stretching to the view’s underlying layer and alleviates the need to use stretchable UIImage objects inside image views.
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 bounds of the view to obtain the appropriate pixel values. The rectangle’s origin point represents the point at which to begin stretching the content. The rectangle’s size values indicate the width and height of the stretchable portion. 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 view. In other words, the stretchable portion starts at the top-left corner of the view and ends at the bottom-right corner. Specifying a size value of 0.0 stretches the single pixel at the current origin point. For example, to stretch a view’s middle pixel only, you could specify an origin of (0.5, 0.5) and a size of (0.0, 0.0).
You can change this property from the default to define a different stretchable area for your content. For example, suppose you have an image view that is 21 pixels wide by 16 pixels high. To make the view stretch horizontally about the middle pixel of its image, you would set the rectangle’s origin point to (10/21, 0.0) and its size to (1/21, 1.0).
UIView.hA Boolean value indicating whether the receiver handles touch events exclusively.
@property(nonatomic, getter=isExclusiveTouch) BOOL exclusiveTouch
If YES, the receiver blocks other views in the same window from receiving touch events; otherwise, it does not. The default value is NO.
UIView.hThe receiver’s frame rectangle.
@property(nonatomic) CGRect frame
Setting the frame rectangle repositions and resizes the receiver within the coordinate system of its superview. The origin of the frame is in superview coordinates. Setting this property changes the values of the center and bounds 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. If the transform property is also set, use the bounds and center properties instead; otherwise, animating changes to the frame property does not correctly reflect the actual location of the view.
Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.
UIView.hA Boolean value that determines whether the receiver is hidden.
@property(nonatomic, getter=isHidden) BOOL hidden
YES if the receiver should be hidden; otherwise, NO. The default value is NO.
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 NO if the receiver is hidden because an ancestor is hidden.
UIView.hThe view’s Core Animation layer used for rendering. (read-only)
@property(nonatomic, readonly, retain) CALayer *layer
This property is never nil. The view is the layer’s delegate.
Warning: Since the view is the layer’s delegate, you should never set the view as a delegate of another CALayer object. Additionally, you should never change the delegate of this layer.
UIView.hA Boolean value indicating whether the receiver handles multi-touch events.
@property(nonatomic, getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled
If YES, the receiver handles multi-touch events; otherwise, it does not. If NO, the receiver is sent only the first touch event in a multi-touch sequence. Other views in the same window can still receive touch events when this property is NO. Set this property and the exclusiveTouch property to YES if this view should handle multi-touch events exclusively—for example, when tracking a sequence of multi-touch events. The default value is NO.
UIView.hA Boolean value that determines whether the receiver is opaque.
@property(nonatomic, getter=isOpaque) BOOL opaque
YES if it is opaque; otherwise, NO. If opaque, the drawing operation assumes that the view fills its bounds and can draw more efficiently. The results are unpredictable if opaque and the view doesn’t fill its bounds. Set this property to NO if the view is fully or partially transparent. The default value is YES.
UIView.hThe receiver’s immediate subviews. (read-only)
@property(nonatomic, readonly, copy) NSArray *subviews
UIView.hThe receiver’s superview, or nil if it has none. (read-only)
@property(nonatomic, readonly) UIView *superview
UIView.hThe receiver’s tag, an integer that you can use to identify view objects in your application.
@property(nonatomic) NSInteger tag
The default value is 0. Subclasses can set this to individual tags.
UIView.hSpecifies the transform applied to the receiver, relative to the center of its bounds.
@property(nonatomic) CGAffineTransform transform
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)
Warning: If this property is not the identity transform, the value of the frame property is undefined and therefore should be ignored.
UIView.hA Boolean value that determines whether user events are ignored and removed from the event queue.
@property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled
If NO, user events—such as touch and keyboard—are ignored and removed from the event queue. The default value is YES.
UIView.hThe receiver’s window object, or nil if it has none. (read-only)
@property(nonatomic, readonly) UIWindow *window
UIView.hReturns a Boolean value indicating whether animations are enabled.
+ (BOOL)areAnimationsEnabled
YES if animations are enabled; otherwise, NO.
UIView.hBegins an animation block.
+ (void)beginAnimations:(NSString *)animationID context:(void *)context
Application-supplied identifier for the animations within a block that is passed to the animation delegate messages—the selectors set using the setAnimationWillStartSelector: and setAnimationDidStopSelector: methods.
Additional application-supplied information that is passed to the animation delegate messages—the selectors set using the setAnimationWillStartSelector: and setAnimationDidStopSelector: methods.
The visual changes caused by setting some property values can be animated in an animation block. Animation blocks can be nested. The setAnimation... class methods do nothing if they are not invoked in an animation block. Use the beginAnimations:context: to begin and the commitAnimations class method to end an animation block.
+ commitAnimations+ setAnimationWillStartSelector:+ setAnimationDidStopSelector:+ setAnimationDelegate:UIView.hEnds an animation block and starts animations when this is the outer animation block.
+ (void)commitAnimations
If the current animation block is the outer animation block, starts animations when the application returns to the run loop. Animations are run in a separate thread so the application is not blocked. In this way, multiple animations can be piled on top of one another. See setAnimationBeginsFromCurrentState: for how to start animations while others are in progress.
UIView.hReturns the class used to create the layer for instances of this class.
+ (Class)layerClass
The class used to create the view’s layer.
Overridden by subclasses to specify a custom class used for rendering. Invoked when creating the underlying layer for a view. The default value is the CALayer class object.
UIView.hSets whether the animation should begin playing from the current state.
+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState
YES if animations should begin from their currently visible state; otherwise, NO.
If set to YES when an animation is in flight, the current view position of the in-flight animation is used as the starting state for the new animation. If set to NO, the in-flight animation ends before the new animation begins using the last view position as the starting state. This method does nothing if an animation is not in flight or invoked outside of an animation block. Use the beginAnimations:context: class method to start and the commitAnimations class method to end an animation block. The default value is NO.
+ beginAnimations:context:+ commitAnimations+ setAnimationStartDate:+ setAnimationDuration:+ setAnimationDelay:+ setAnimationCurve:+ setAnimationRepeatCount:+ setAnimationRepeatAutoreverses:UIView.hSets the curve of animating property changes within an animation block.
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve
The animation curve is the relative speed of the animation over its course. This method does nothing if invoked outside of an animation block. Use the beginAnimations:context: class method to start and the commitAnimations class method to end an animation block. The default value of the animation curve is UIViewAnimationCurveEaseInOut.
+ beginAnimations:context:+ commitAnimations+ setAnimationStartDate:+ setAnimationDuration:+ setAnimationDelay:+ setAnimationRepeatCount:+ setAnimationRepeatAutoreverses:+ setAnimationBeginsFromCurrentState:UIView.hSets the delay (in seconds) of animating property changes within an animation block.
+ (void)setAnimationDelay:(NSTimeInterval)delay
This method does nothing if invoked outside of an animation block. Use the beginAnimations:context: class method to start and the commitAnimations class method to end an animation block. The default value of the animation delay is 0.0.
+ beginAnimations:context:+ commitAnimations+ setAnimationStartDate:+ setAnimationDuration:+ setAnimationCurve:+ setAnimationRepeatCount:+ setAnimationRepeatAutoreverses:+ setAnimationBeginsFromCurrentState:UIView.hSets the delegate for animation messages.
+ (void)setAnimationDelegate:(id)delegate
The object that receives the delegate messages set using the setAnimationWillStartSelector: and setAnimationDidStopSelector: methods.
This method does nothing if invoked outside of an animation block. Use the beginAnimations:context: class method to start and the commitAnimations class method to end an animation block. The default value is nil.
+ beginAnimations:context:+ commitAnimations+ setAnimationWillStartSelector:+ setAnimationDidStopSelector:UIView.hSets the message to send to the animation delegate when animation stops.
+ (void)setAnimationDidStopSelector:(SEL)selector
The message sent to the animation delegate after animations end. The default value is NULL. The selector should be of the form: - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context. Your method must take the following arguments:
animationID
An NSString containing an optional application-supplied identifier. This is the identifier that is passed to the beginAnimations:context: method. This argument can be nil.
finished
An NSNumber object containing a Boolean value. The value is YES if the animation ran to completion before it stopped or NO if it did not.
context
An optional application-supplied context. This is the context data passed to the beginAnimations:context: method. This argument can be nil.
This method does nothing if invoked outside of an animation block. Use the beginAnimations:context: class method to start and the commitAnimations class method to end an animation block. The default value is NULL.
+ beginAnimations:context:+ commitAnimations+ setAnimationDelegate:+ setAnimationWillStartSelector:UIView.hSets the duration (in seconds) of animating property changes within an animation block.
+ (void)setAnimationDuration:(NSTimeInterval)duration
The period over which the animation occurs.
This method does nothing if invoked outside of an animation block. Use the beginAnimations:context: class method to start and the commitAnimations class method to end an animation block. The default value is 0.2.
+ beginAnimations:context:+ commitAnimations+ setAnimationStartDate:+ setAnimationDelay:+ setAnimationCurve:+ setAnimationRepeatCount:+ setAnimationRepeatAutoreverses:+ setAnimationBeginsFromCurrentState:UIView.hSets whether the animation of property changes within an animation block automatically reverses repeatedly.
+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses
If YES if the animation automatically reverses repeatedly; if NO, it does not.
Autoreverses is when the animation plays backward after playing forward and similarly plays forward after playing backward. Use the setAnimationRepeatCount: class method to specify the number of times the animation autoreverses. This method does nothing if the repeat count is zero or this method is invoked outside of an animation block. Use the beginAnimations:context: class method to start and the commitAnimations class method to end an animation block. The default value is NO.
+ beginAnimations:context:+ commitAnimations+ setAnimationStartDate:+ setAnimationDuration:+ setAnimationDelay:+ setAnimationCurve:+ setAnimationRepeatCount:+ setAnimationBeginsFromCurrentState:UIView.hSets the number of times animations within an animation block repeat.
+ (void)setAnimationRepeatCount:(float)repeatCount
The number of times animations repeat. This value can be a fraction.
This method does nothing if invoked outside of an animation block. Use the beginAnimations:context: class method to start and the commitAnimations class method to end an animation block. By default, animations don’t repeat.
+ beginAnimations:context:+ commitAnimations+ setAnimationStartDate:+ setAnimationDuration:+ setAnimationDelay:+ setAnimationCurve:+ setAnimationRepeatAutoreverses:+ setAnimationBeginsFromCurrentState:UIView.hSets whether animations are enabled.
+ (void)setAnimationsEnabled:(BOOL)enabled
If YES, animations are enabled; if NO, they are not.
Animation attribute changes are ignored when animations are disabled. By default, animations are enabled.
UIView.hSets the start time of animating property changes within an animation block.
+ (void)setAnimationStartDate:(NSDate *)startTime
The time to begin the animations.
Use the beginAnimations:context: class method to start and the commitAnimations class method to end an animation block.
The default start time is the value returned by the CFAbsoluteTimeGetCurrent function.
+ beginAnimations:context:+ commitAnimations+ setAnimationDuration:+ setAnimationDelay:+ setAnimationCurve:+ setAnimationRepeatCount:+ setAnimationRepeatAutoreverses:+ setAnimationBeginsFromCurrentState:UIView.hSets a transition to apply to a view during an animation block.
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache
A transition to apply to view. Possible values are described in UIViewAnimationTransition.
The view to apply the transition to.
If YES, the before and after images of view are rendered once and used to create the frames in the animation. Caching can improve performance but if you set this parameter to YES, you must not update the view or its subviews during the transition. Updating the view and its subviews may interfere with the caching behaviors and cause the view contents to be rendered incorrectly (or in the wrong location) during the animation. You must wait until the transition ends to update the view.
If NO, the view and its contents must be updated for each frame of the transition animation, which may noticeably affect the frame rate.
If you want to change the appearance of a view during a transition—for example, flip from one view to another—then use a container view, an instance of UIView, as follows:
Begin an animation block.
Set the transition on the container view.
Remove the subview from the container view.
Add the new subview to the container view.
Commit the animation block.
UIView.hSets the message to send to the animation delegate when animation starts.
+ (void)setAnimationWillStartSelector:(SEL)selector
The message sent to the animation delegate before animations start. The default value is NULL. The selector should have the same arguments as the beginAnimations:context: method, an optional application-supplied identifier and context. Both of these arguments can be nil.
This method does nothing if invoked outside of an animation block. Use the beginAnimations:context: class method to start and the commitAnimations class method to end an animation block.
+ beginAnimations:context:+ commitAnimations+ setAnimationDelegate:+ setAnimationDidStopSelector:UIView.hAdds a view to the receiver’s subviews so it’s displayed above its siblings.
- (void)addSubview:(UIView *)view
This method also sets the receiver as the next responder of view. The receiver retains view. If you use removeFromSuperview to remove view from the view hierarchy, view is released. If you want to keep using view after removing it from the view hierarchy (if, for example, you are swapping through a number of views), you must retain it before invoking removeFromSuperview.
Views can have only one superview. If the superview of view is not nil and is not the same as the current view, this method removes it from the previous superview before making it a subview of the current view.
– insertSubview:atIndex:– insertSubview:aboveSubview:– insertSubview:belowSubview:– exchangeSubviewAtIndex:withSubviewAtIndex:UIView.hMoves the specified subview to the front of its siblings.
- (void)bringSubviewToFront:(UIView *)view
The subview to move to the front.
UIView.hConverts a point from the coordinate system of a given view to that of the receiver.
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view
A point specifying a location in the coordinate system of 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.
The point converted to the coordinate system of the receiver.
UIView.hConverts a point from the receiver’s coordinate system to that of a given view.
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view
A point specifying a location in the coordinate system of the receiver.
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.
The point converted to the coordinate system of view.
UIView.hConverts a rectangle from the coordinate system of another view to that of the receiver.
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view
The rectangle in view's coordinate system.
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.
The converted rectangle.
UIView.hConverts a rectangle from the receiver’s coordinate system to that of another view.
- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view
A rectangle in the receiver's coordinate system.
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.
The converted rectangle.
UIView.hTells the view when subviews are added.
- (void)didAddSubview:(UIView *)subview
The view that was added as a subview.
Overridden by subclasses to perform additional actions when subviews are added to the receiver. This method is invoked by addSubview:.
UIView.hInforms the receiver that its superview has changed (possibly to nil).
- (void)didMoveToSuperview
The default implementation does nothing; subclasses can override this method to perform whatever actions are necessary.
UIView.hInforms the receiver that it has been added to a window.
- (void)didMoveToWindow
The default implementation does nothing; subclasses can override this method to perform whatever actions are necessary.
The window property may be nil when this method is invoked, 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.
UIView.hDraws the receiver’s image within the passed-in rectangle.
- (void)drawRect:(CGRect)rect
A rectangle defining the area to restrict drawing to.
Subclasses override this method if they actually draw their views. Subclasses need not override this method if the subclass is a container for other views. The default implementation does nothing. If your custom view is a direct UIView subclass, you do not need to call the implementation of super. Note that it is the responsibility of each subclass to totally fill rect if its superclass’s implementation actually draws and opaque is YES.
When this method is invoked, the receiver can assume the coordinate transformations of its frame and bounds rectangles have been applied; all it needs to do is invoke rendering client functions. Use the UIGraphicsGetCurrentContext function to get the current graphics context for drawing that also has the coordinate origin in the upper-left corner. Do not retain the graphics context since it can change between calls to the drawRect: method.
UIView.hCauses the view (or one of its embedded text fields) to resign the first responder status.
- (BOOL)endEditing:(BOOL)force
If YES, force the first responder to resign, regardless of whether it wants to do so.
YES if the view resigned the first responder status or NO if it did not.
This method looks at the view and its subview hierarchy for a 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 YES, the text field is never even asked; it is forced to resign.
UITextField.hExchanges the subviews in the receiver at the given indices.
- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2
The index of the subview with which to replace the subview at index index2.
The index of the subview with which to replace the subview at index index1.
UIView.hReturns the farthest descendant of the receiver in the view hierarchy (including itself) that contains a specified point.
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
A point that is in the receiver’s coordinate system.
The event that triggered this method or nil if this method is invoked programmatically.
A view object that is the farthest descendent of point. Returns nil if the point lies completely outside the receiver.
This method traverses the view hierarchy by sending the pointInside:withEvent: message to each subview to determine which subview should receive a touch event. If pointInside:withEvent: returns YES, then the subview’s hierarchy is traversed; otherwise, its branch of the view hierarchy is ignored. You rarely need to invoke this method, but you might override it to hide touch events from subviews.
This method ignores views that are hidden, that have disabled user interaction, or have an alpha level less than 0.1.
UIView.hInitializes and returns a newly allocated view object with the specified frame rectangle.
- (id)initWithFrame:(CGRect)aRect
The frame rectangle for the created view object. The origin of the frame is in superview coordinates. Setting this property changes the values of the center and bounds properties accordingly.
An initialized view object or nil if the object couldn't be created.
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.
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.
UIView.hInserts a view above another view in the view hierarchy.
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview
The view to insert above another view. It’s removed from its superview if it’s not a sibling of siblingSubview.
The sibling view that will be behind the inserted view.
Views can have only one superview. If the superview of view is not nil and is not the same as the current view, this method removes it from the previous superview before making it a subview of the current view.
– addSubview:– insertSubview:atIndex:– insertSubview:belowSubview:– exchangeSubviewAtIndex:withSubviewAtIndex:UIView.hInserts a subview at the specified index.
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index
The view to insert. This value cannot be nil.
Subview indices start at 0 and cannot be greater than the number of subviews.
Views can have only one superview. If the superview of view is not nil and is not the same as the current view, this method removes it from the previous superview before making it a subview of the current view.
– addSubview:– insertSubview:aboveSubview:– insertSubview:belowSubview:– exchangeSubviewAtIndex:withSubviewAtIndex:UIView.hInserts a view below another view in the view hierarchy.
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview
The view to insert below another view. It’s removed from its superview if it’s not a sibling of siblingSubview.
The sibling view that will be above the inserted view.
Views can have only one superview. If the superview of view is not nil and is not the same as the current view, this method removes it from the previous superview before making it a subview of the current view.
– addSubview:– insertSubview:atIndex:– insertSubview:aboveSubview:– exchangeSubviewAtIndex:withSubviewAtIndex:UIView.hReturns a Boolean value indicating whether the receiver is a subview of a given view or whether it is identical to that view.
- (BOOL)isDescendantOfView:(UIView *)view
The view to test for subview relationship within the view hierarchy.
YES if the receiver is an immediate or distant subview of view, or if view is the receiver; otherwise NO.
UIView.hLays out the subviews if needed.
- (void)layoutIfNeeded
Use this method to force the layout of subviews before drawing. Starting with the receiver, this method traverses upward through the view hierarchy as long as superviews require layout. Then it lays out the entire tree beneath that ancestor. Therefore, calling this method can potentially force the layout of your entire view hierarchy. The UIView implementation of this calls the equivalent CALayer method and so has the same behavior as CALayer.
UIView.hLays out subviews.
- (void)layoutSubviews
Overridden by subclasses to layout subviews when layoutIfNeeded is invoked. The default implementation of this method does nothing.
UIView.hReturns a Boolean value indicating whether the receiver contains the specified point.
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
A point that is in the receiver’s coordinate system.
The event that triggered this method or nil if this method is invoked programmatically.
YES if point is inside the receiver’s bounds; otherwise, NO.
UIView.hUnlinks the receiver from its superview and its window, and removes it from the responder chain.
- (void)removeFromSuperview
If the receiver’s superview is not nil, this method releases the receiver. If you plan to reuse the view, be sure to retain it before calling this method and be sure to release it as appropriate when you are done with it or after adding it to another view hierarchy.
Never invoke this method while displaying.
UIView.hMoves the specified subview to the back of its siblings.
- (void)sendSubviewToBack:(UIView *)view
The subview to move to the back.
UIView.hControls whether the receiver's entire bounds rectangle is marked as needing display.
- (void)setNeedsDisplay
By default, geometry changes to a view automatically redisplays the view without needing to invoke the drawRect: method. Therefore, you need to request that a view redraw only when the data or state used for drawing a view changes. In this case, send the view the setNeedsDisplay message. Any UIView objects marked as needing display are automatically redisplayed when the application returns to the run loop.
UIView.hMarks the region of the receiver within the specified rectangle as needing display, increasing the receiver’s existing invalid region to include it.
- (void)setNeedsDisplayInRect:(CGRect)invalidRect
The rectangular region of the receiver to mark as invalid; it should be specified in the coordinate system of the receiver.
By default, geometry changes to a view automatically redisplays the view without needing to invoke the drawRect: method. Therefore, you need to request that a view or a region of a view redraw only when the data or state used for drawing a view changes. Use this method or the setNeedsDisplay method to mark a view as needing display.
UIView.hSets whether subviews need to be rearranged before displaying.
- (void)setNeedsLayout
If you invoke this method before the next display operation, then layoutIfNeeded lays out the subviews; otherwise, it does not.
UIView.hAsks the view to calculate and return the size that best fits its subviews.
- (CGSize)sizeThatFits:(CGSize)size
The current size of the receiver.
A new size that fits the receiver’s subviews.
The default implementation of this method simply returns the value in the size parameter. However, 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.
UIView.hResizes and moves the receiver view so it just encloses its subviews.
- (void)sizeToFit
Call this method when you want to resize the current view so that it uses the most appropriate amount of space. Specific UIKit views size 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.
UIView.hReturns the view with the specified tag.
- (UIView *)viewWithTag:(NSInteger)tag
The tag used to search for the view.
The view in the receiver’s hierarchy that matches tag. The receiver is included in the search.
UIView.hInforms the receiver that its superview is about to change to the specified superview (which may be nil).
- (void)willMoveToSuperview:(UIView *)newSuperview
A view object that will be the new superview of the receiver.
Subclasses can override this method to perform whatever actions are necessary.
UIView.hInforms the receiver that it’s being added to the view hierarchy of the specified window object (which may be nil).
- (void)willMoveToWindow:(UIWindow *)newWindow
A window object that will be at the root of the receiver's new view hierarchy.
Subclasses can override this method to perform whatever actions are necessary.
UIView.hOverridden by subclasses to perform additional actions before subviews are removed from the receiver.
- (void)willRemoveSubview:(UIView *)subview
The subview that will be removed.
This method is invoked when subview receives a removeFromSuperview message or subview is removed from the receiver because it is being added to another view.
UIView.hSpecifies the animation curve. For example, specifies whether animation changes speed at the beginning or end.
typedef enum {
UIViewAnimationCurveEaseInOut,
UIViewAnimationCurveEaseIn,
UIViewAnimationCurveEaseOut,
UIViewAnimationCurveLinear
} UIViewAnimationCurve;
UIViewAnimationCurveEaseInOutAn 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 iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewAnimationCurveEaseInAn ease-in curve causes the animation to begin slowly, and then speed up as it progresses.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewAnimationCurveEaseOutAn ease-out curve causes the animation to begin quickly, and then slow as it completes.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewAnimationCurveLinearA linear animation curve causes an animation to occur evenly over its duration.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIView.hSpecifies how a view resizes its subviews when its size changes.
typedef enum {
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit,
UIViewContentModeScaleAspectFill,
UIViewContentModeRedraw,
UIViewContentModeCenter,
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
} UIViewContentMode;
UIViewContentModeScaleToFillScales the content to fit the size of itself by changing the aspect ratio of the content if necessary.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewContentModeScaleAspectFitScales 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 iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewContentModeScaleAspectFillScales 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 iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewContentModeRedrawRedisplays the view when the bounds change by invoking the setNeedsDisplay method.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewContentModeCenterCenters the content in the view’s bounds, keeping the proportions the same.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewContentModeTopCenters the content aligned at the top in the view’s bounds.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewContentModeBottomCenters the content aligned at the bottom in the view’s bounds.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewContentModeLeftAligns the content on the left of the view.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewContentModeRightAligns the content on the right of the view.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewContentModeTopLeftAligns the content in the top-left corner of the view.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewContentModeTopRightAligns the content in the top-right corner of the view.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewContentModeBottomLeftAligns the content in the bottom-left corner of the view.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewContentModeBottomRightAligns the content in the bottom-right corner of the view.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIView.hSpecifies how a view is automatically resized.
enum {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
typedef NSUInteger UIViewAutoresizing;
UIViewAutoresizingNoneThe view does not resize.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewAutoresizingFlexibleLeftMarginThe view resizes by expanding or shrinking in the direction of the left margin.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewAutoresizingFlexibleWidthThe view resizes by expanding or shrinking its width.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewAutoresizingFlexibleRightMarginThe view resizes by expanding or shrinking in the direction of the right margin.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewAutoresizingFlexibleTopMarginThe view resizes by expanding or shrinking in the direction of the top margin.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewAutoresizingFlexibleHeightThe view resizes by expanding or shrinking its height.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewAutoresizingFlexibleBottomMarginThe view resizes by expanding or shrinking in the direction of the bottom margin.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIView.hSpecifies a transition to apply to a view in an animation block.
typedef enum {
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
} UIViewAnimationTransition;
UIViewAnimationTransitionNoneNo transition specified.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewAnimationTransitionFlipFromLeftA 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 iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewAnimationTransitionFlipFromRightA 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 iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewAnimationTransitionCurlUpA transition that curls a view up from the bottom.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIViewAnimationTransitionCurlDownA transition that curls a view down from the top.
Available in iPhone OS 2.0 and later.
Declared in UIView.h.
UIView.hLast updated: 2009-11-17