iPhone OS Reference Library Apple Developer Connection spyglass button

UIKit Function Reference

Framework
UIKit/UIKit.h
Declared in
UIAccessibility.h
UIApplication.h
UIDevice.h
UIGeometry.h
UIGraphics.h
UIImage.h
UIImagePickerController.h

Overview

The UIKit framework defines a number of functions, many of them used in graphics and drawing operations.

Functions by Task

Application Launch

Image Manipulation

Movie Saving

Graphics

String Conversions

Setting Edge Insets

Interface Orientation Macros

Device Orientation Macros

Accessibility Notification

Functions

CGAffineTransformFromString

Returns a Core Graphics affine transform structure corresponding to the data in a given string.

CGAffineTransform CGAffineTransformFromString (
   NSString *string
);
Parameters
string

A string object whose contents are of the form “{a, b, c, d, tx, ty}”, where a, b, c, d, tx, and ty are the floating-point component values of the CGAffineTransform data structure. An example of a valid string is @”{1,0,0,1,2.5,3.0}”. The string is not localized, so items are always separate with a comma. For information about the position of each value in the transform array, see CGAffineTransform Reference.

Return Value

A Core Graphics affine transform structure. If the string is not well-formed, the function returns the identity transform.

Discussion

In general, you should use this function only to convert strings that were previously created using the NSStringFromCGAffineTransform function.

Availability
See Also
Declared In
UIGeometry.h

CGPointFromString

Returns a Core Graphics point structure corresponding to the data in a given string.

CGPoint CGPointFromString (
   NSString *string
);
Parameters
string

A string object whose contents are of the form “{x,y}”, where x is the x coordinate and y is the y coordinate. The x and y values can represent integer or float values. An example of a valid string is @”{3.0,2.5}”. The string is not localized, so items are always separate with a comma.

Return Value

A Core Graphics structure that represents a point. If the string is not well-formed, the function returns CGPointZero.

Discussion

In general, you should use this function only to convert strings that were previously created using the NSStringFromCGPoint function.

Availability
See Also
Declared In
UIGeometry.h

CGRectFromString

Returns a Core Graphics rectangle structure corresponding to the data in a given string.

CGRect CGRectFromString (
   NSString *string
);
Parameters
string

A string object whose contents are of the form “{{x,y},{w, h}}”, where x is the x coordinate, y is the y coordinate, w is the width, and h is the height. These components can represent integer or float values. An example of a valid string is @”{{3,2},{4,5}}”. The string is not localized, so items are always separate with a comma.

Return Value

A Core Graphics structure that represents a rectangle. If the string is not well-formed, the function returns CGRectZero.

Discussion

In general, you should use this function only to convert strings that were previously created using the NSStringFromCGRect function.

Availability
See Also
Declared In
UIGeometry.h

CGSizeFromString

Returns a Core Graphics size structure corresponding to the data in a given string.

CGSize CGSizeFromString (
   NSString *string
);
Parameters
string

A string object whose contents are of the form “{w, h}”, where w is the width and h is the height. The w and h values can be integer or float values. An example of a valid string is @”{3.0,2.5}”. The string is not localized, so items are always separate with a comma.

Return Value

A Core Graphics structure that represents a size. If the string is not well-formed, the function returns CGSizeZero.

Discussion

In general, you should use this function only to convert strings that were previously created using the NSStringFromCGSize function.

Availability
See Also
Declared In
UIGeometry.h

NSStringFromCGAffineTransform

Returns a string object formatted to contain the data from an affine transform.

NSString *NSStringFromCGAffineTransform(CGAffineTransform transform);
Parameters
transform

A Core Graphics affine transform structure.

Return Value

A string object that corresponds to transform. See CGAffineTransformFromString for a discussion of the string format.

Availability
See Also
Declared In
UIGeometry.h

NSStringFromCGPoint

Returns a string object formatted to contain the data from a point.

NSString * NSStringFromCGPoint (
   CGPoint point
);
Parameters
point

A Core Graphics structure representing a point.

Return Value

A string object that corresponds to point. See CGPointFromString for a discussion of the string format.

Availability
See Also
Declared In
UIGeometry.h

NSStringFromCGRect

Returns a string object formatted to contain the data from a rectangle.

NSString * NSStringFromCGRect (
   CGRect rect
);
Parameters
rect

A Core Graphics structure representing a rectangle.

Return Value

A string object that corresponds to rect. See CGRectFromString for a discussion of the string format.

Availability
See Also
Declared In
UIGeometry.h

NSStringFromCGSize

Returns a string object formatted to contain the data from a size data structure.

NSString * NSStringFromCGSize (
   CGSize size
);
Parameters
size

A Core Graphics structure representing a size.

Return Value

A string object that corresponds to size. See CGSizeFromString for a discussion of the string format.

Availability
See Also
Declared In
UIGeometry.h

NSStringFromUIEdgeInsets

Returns a string object formatted to contain the data from an edge insets structure.

NSString *NSStringFromUIEdgeInsets(UIEdgeInsets insets);
Parameters
insets

A UIKit edge insets data structure.

Return Value

A string object that corresponds to insets. See UIEdgeInsetsFromString for a discussion of the string format.

Availability
See Also
Declared In
UIGeometry.h

UIAccessibilityPostNotification

Posts a notification to assistive applications.

void UIAccessibilityPostNotification(UIAccessibilityNotifications notification, id argument);
Parameters
notification

The notification to post (see “Notifications” in UIAccessibility Protocol Reference for a list of notifications).

argument

The argument specified by the notification. Pass nil unless a notification specifies otherwise.

Discussion

Your application might need to post accessibility notifications if you have user interface components that change very frequently or that appear and disappear.

Availability
Related Sample Code
Declared In
UIAccessibility.h

UIApplicationMain

This function is called in the main entry point to create the application object and the application delegate and set up the event cycle.

int UIApplicationMain (
   int argc,
   char *argv[],
   NSString *principalClassName,
   NSString *delegateClassName
);
Parameters
argc

The count of arguments in argv; this usually is the corresponding parameter to main.

argv

A variable list of arguments; this usually is the corresponding parameter to main.

principalClassName

The name of the UIApplication class or subclass. If you specify nil, UIApplication is assumed.

delegateClassName

The name of the class from which the application delegate is instantiated. If principalClassName designates a subclass of UIApplication, you may designate the subclass as the delegate; the subclass instance receives the application-delegate messages. Specify nil if you load the delegate object from your application’s main nib file.

Return Value

Even though an integer return type is specified, this function never returns. When users terminate an iPhone application by pressing the Home button, the application immediately exits by calling the exit system function with an argument of zero.

Discussion

This function instantiates the application object from the principal class and and instantiates the delegate (if any) from the given class and sets the delegate for the application. It also sets up the main event loop, including the application’s run loop, and begins processing events. If the application’s Info.plist file specifies a main nib file to be loaded, by including the NSMainNibFile key and a valid nib file name for the value, this function loads that nib file.

Despite the declared return type, this function never returns. For more information on how this function behaves, see “The Core Application” in iPhone Application Programming Guide.

Availability
Related Sample Code
Declared In
UIApplication.h

UIDeviceOrientationIsLandscape

Returns a Boolean value indicating whether the device is in a landscape orientation.

#define UIDeviceOrientationIsLandscape(orientation) \
   ((orientation) == UIDeviceOrientationLandscapeLeft || \
   (orientation) == UIDeviceOrientationLandscapeRight)
Parameters
orientation

Specify the value of the orientation property of the UIDevice class.

Return Value

Returns YES if the device orientation is landscape, otherwise returns NO.

Availability
Related Sample Code
Declared In
UIDevice.h

UIDeviceOrientationIsPortrait

Returns a Boolean value indicating whether the device is in a portrait orientation.

#define UIDeviceOrientationIsPortrait(orientation)  \
   ((orientation) == UIDeviceOrientationPortrait || \
   (orientation) == UIDeviceOrientationPortraitUpsideDown)
Parameters
orientation

Specify the value of the orientation property of the UIDevice class.

Return Value

Returns YES if the device orientation is portrait, otherwise returns NO.

Availability
Declared In
UIDevice.h

UIDeviceOrientationIsValidInterfaceOrientation

Returns a Boolean value indicating whether the specified orientation constant is valid.

#define UIDeviceOrientationIsValidInterfaceOrientation(orientation) \
   ((orientation) == UIDeviceOrientationPortrait || \
   (orientation) == UIDeviceOrientationPortraitUpsideDown || \
   (orientation) == UIDeviceOrientationLandscapeLeft || \
   (orientation) == UIDeviceOrientationLandscapeRight)
Parameters
orientation

Specify the orientation constant to check.

Return Value

Returns YES if the specified orientation constant is valid or NO if it is not valid.

Availability
Declared In
UIApplication.h

UIEdgeInsetsEqualToEdgeInsets

Compares two edge insets to determine if they are the same.

BOOL UIEdgeInsetsEqualToEdgeInsets (
   UIEdgeInsets insets1,
   UIEdgeInsets insets2
);
Parameters
insets1

An edge inset to compare with insets2.

insets2

An edge inset to compare with insets1.

Return Value

YES if the edge insets are the same; otherwise, NO.

Availability
See Also
Declared In
UIGeometry.h

UIEdgeInsetsFromString

Returns a UIKit edge insets structure corresponding to the data in a given string.

UIEdgeInsets UIEdgeInsetsFromString (
   NSString *string
);
Parameters
string

A string object whose contents are of the form “{top, left, bottom, right}”, where top, left, bottom, right are the floating-point component values of the UIEdgeInsets structure. An example of a valid string is @”{3.0,8.0,3.0,5.0}”. The string is not localized, so items are always separate with a comma.

Return Value

An edge insets data structure. If the string is not well-formed, the function returns UIEdgeInsetsZero.

Discussion

In general, you should use this function only to convert strings that were previously created using the NSStringFromUIEdgeInsets function.

Availability
See Also
Declared In
UIGeometry.h

UIEdgeInsetsInsetRect

Adjusts a rectangle by the given edge insets.

CGRect UIEdgeInsetsInsetRect (
   CGRect rect,
   UIEdgeInsets insets
);
Parameters
rect

The rectangle to be adjusted.

insets

The edge insets to be applied to the adjustment.

Return Value

A rectangle that is adjusted by the UIEdgeInsets structure passed in insets. i

Discussion

This inline function increments the origin of rect and decrements the size of rect by applying the appropriate member values of the UIEdgeInsets structure.

Availability
See Also
Declared In
UIGeometry.h

UIEdgeInsetsMake

Creates an edge inset for a button or view.

UIEdgeInsets UIEdgeInsetsMake (
   CGFloat top,
   CGFloat left,
   CGFloat bottom,
   CGFloat right
);
Parameters
top

The inset at the top of an object.

left

The inset on the left of an object

bottom

The inset on the bottom of an object.

right

The inset on the right of an object.

Return Value

An inset for a button or view

Discussion

An inset is a margin around the drawing rectangle where each side (left, right, top, and bottom) can have a different value.

Availability
See Also
Declared In
UIGeometry.h

UIGraphicsBeginImageContext

Creates a bitmap-based graphics context and makes it the current context.

void UIGraphicsBeginImageContext(CGSize size);
Parameters
size

The size of the new bitmap context. This represents the size of the image returned by the UIGraphicsGetImageFromCurrentImageContext function.

Discussion

You use this function to configure the drawing environment for rendering into a bitmap. This drawing environment uses the premultiplied RGBA format to store the resulting bitmap data. The environment also uses the default coordinate system for UIKit views, where the origin is in the upper-left corner and the positive axes extend down and to the right of the origin. The drawing environment is pushed onto the graphics context stack immediately.

While the context created by this function is the current context, you can call the UIGraphicsGetImageFromCurrentImageContext function to retrieve an image object based on the current contents of the context. When you are done modifying the context, you must call the UIGraphicsEndImageContext function to clean up the bitmap drawing environment and remove the graphics context from the top of the context stack. You should not use the UIGraphicsPopContext function to remove this type of context from the stack.

In most other respects, the graphics context created by this function behaves like any other graphics context. You can change the context by pushing and popping other graphics contexts. You can also get the bitmap context using the UIGraphicsGetCurrentContext function.

Availability
See Also
Related Sample Code
Declared In
UIGraphics.h

UIGraphicsEndImageContext

Removes the current bitmap-based graphics context from the top of the stack.

void UIGraphicsEndImageContext(void);
Discussion

You use this function to clean up the drawing environment put in place by the UIGraphicsBeginImageContext function and to remove the corresponding bitmap-based graphics context from the top of the stack. If the current context was not created using the UIGraphicsBeginImageContext function, this method does nothing.

Availability
See Also
Related Sample Code
Declared In
UIGraphics.h

UIGraphicsGetCurrentContext

Returns the current graphics context.

CGContextRef UIGraphicsGetCurrentContext (
   void
);
Return Value

The current graphics context.

Discussion

The current graphics context is nil by default. Prior to calling its drawRect: method, view objects push a valid context onto the stack, making it current. If you are not using a UIView object to do your drawing, however, you must push a valid context onto the stack manually using the UIGraphicsPushContext function.

You should call this function from the main thread of your application only.

Availability
See Also
Related Sample Code
Declared In
UIGraphics.h

UIGraphicsGetImageFromCurrentImageContext

Returns an image based on the contents of the current bitmap-based graphics context.

UIImage* UIGraphicsGetImageFromCurrentImageContext(void);
Return Value

An autoreleased image object containing the contents of the current bitmap graphics context.

Discussion

You should call this function only when a bitmap-based graphics context is the current graphics context. If the current context is nil or was not created by a call to UIGraphicsBeginImageContext, this function returns nil.

Availability
See Also
Related Sample Code
Declared In
UIGraphics.h

UIGraphicsPopContext

Removes the current graphics context from the top of the stack, restoring the previous context.

void UIGraphicsPopContext (
   void
);
Discussion

Use this function to balance calls to the UIGraphicsPushContext function.

You should call this function from the main thread of your application only.

Availability
See Also
Declared In
UIGraphics.h

UIGraphicsPushContext

Makes the specified graphics context the current context.

void UIGraphicsPushContext (
   CGContextRef context
);
Parameters
context

The graphics context to make the current context.

Discussion

You can use this function to save the previous graphics state and make the specified context the current context. You must balance calls to this function with matching calls to the UIGraphicsPopContext function.

You should call this function from the main thread of your application only.

Availability
See Also
Declared In
UIGraphics.h

UIImageJPEGRepresentation

Returns the data for the specified image in JPEG format.

NSData * UIImageJPEGRepresentation (
   UIImage *image,
   CGFloat compressionQuality
);
Parameters
image

The original image data.

compressionQuality

The quality of the resulting JPEG image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality).

Return Value

An autoreleased data object containing the JPEG data, or nil if there was a problem generating the data. This function may return nil if the image has no data or if the underlying CGImageRef contains data in an unsupported bitmap format.

Discussion

If the image object’s underlying image data has been purged, calling this method forces that data to be reloaded into memory.

Availability
Declared In
UIImage.h

UIImagePNGRepresentation

Returns the data for the specified image in PNG format

NSData * UIImagePNGRepresentation (
   UIImage *image
);
Parameters
image

The original image data.

Return Value

An autoreleased data object containing the PNG data, or nil if there was a problem generating the data. This function may return nil if the image has no data or if the underlying CGImageRef contains data in an unsupported bitmap format.

Discussion

If the image object’s underlying image data has been purged, calling this method forces that data to be reloaded into memory.

Availability
Related Sample Code
Declared In
UIImage.h

UIImageWriteToSavedPhotosAlbum

Adds the specified image to the user’s Saved Photos album.

void UIImageWriteToSavedPhotosAlbum (
   UIImage  *image,
   id       completionTarget,
   SEL      completionSelector,
   void     *contextInfo
);
Parameters
image

The image to write to the user’s device.

completionTarget

The object whose selector should be called after the image has been written to the user’s device.

completionSelector

The method selector, of the target object, to call. This optional method should be of the form:

- (void) image: (UIImage *) image
    didFinishSavingWithError: (NSError *) error
    contextInfo: (void *) contextInfo;
contextInfo

An optional pointer to any context-specific data that you want passed to the completion selector.

Discussion

The use of the completionTarget, completionSelector, and contextInfo parameters is optional and necessary only if you want to be notified asynchronously when the function finishes writing the image to the user’s Saved Photos album. If you do not want to be notified, pass nil for these parameters.

Availability
Declared In
UIImagePickerController.h

UIInterfaceOrientationIsLandscape

Returns a Boolean value indicating whether the user interface is currently presented in a landscape orientation.

#define UIInterfaceOrientationIsLandscape(orientation) \
   ((orientation) == UIInterfaceOrientationLandscapeLeft || \
   (orientation) == UIInterfaceOrientationLandscapeRight)
Parameters
orientation

Specify the orientation constant to check.

Return Value

Returns YES if the interface orientation is landscape, otherwise returns NO.

Discussion

The interface orientation can be different than the device orientation. You typically use this macro in your view controller code to check the current orientation.

Availability
Related Sample Code
Declared In
UIApplication.h

UIInterfaceOrientationIsPortrait

Returns a Boolean value indicating whether the user interface is currently presented in a portrait orientation.

#define UIInterfaceOrientationIsPortrait(orientation) \
   ((orientation) == UIInterfaceOrientationPortrait || \
   (orientation) == UIInterfaceOrientationPortraitUpsideDown)
Parameters
orientation

Specify the orientation constant to check.

Return Value

Returns YES if the interface orientation is portrait, otherwise returns NO.

Discussion

The interface orientation can be different than the device orientation. You typically use this macro in your view controller code to check the current orientation.

Availability
Declared In
UIApplication.h

UIRectClip

Modifies the current clipping path by intersecting it with the specified rectangle.

void UIRectClip (
   CGRect rect
);
Parameters
rect

The rectangle to intersect with the clipping region. If the width or height of the rectangle are less than 0, this function does not change the clipping path.

Discussion

Each call to this function permanently shrinks the clipping path of the current graphics context using the specified rectangle. You cannot use this function to expand the clipping region path. If the current graphics context is nil, this method does nothing.

If you need to return the clipping path to its original shape in your drawing code, you should save the current graphics context before calling this function. To save the current context, push a new graphics context onto the top of the stack using the UIGraphicsPushContext function. When you are ready to restore the original clipping region, you can then use the UIGraphicsPopContext function to remove the current context and restore the previous graphics state.

You should call this function from the main thread of your application only.

Availability
See Also
Related Sample Code
Declared In
UIGraphics.h

UIRectFill

Fills the specified rectangle with the current color.

void UIRectFill (
   CGRect rect
);
Parameters
rect

The rectangle defining the area in which to draw.

Discussion

Fills the specified rectangle using the fill color of the current graphics context and the kCGBlendModeCopy blend mode.

You should call this function from the main thread of your application only.

Availability
Related Sample Code
Declared In
UIGraphics.h

UIRectFillUsingBlendMode

Fills a rectangle with the current fill color using the specified blend mode.

void UIRectFillUsingBlendMode (
   CGRect rect,
   CGBlendMode blendMode
);
Parameters
rect

The rectangle defining the area in which to draw.

blendMode

The blend mode to use during drawing.

Discussion

This function draws the rectangle in the current graphics context. If the current graphics context is nil, this method does nothing.

You should call this function from the main thread of your application only.

Availability
Declared In
UIGraphics.h

UIRectFrame

Draws a frame around the inside of the specified rectangle.

void UIRectFrame (
   CGRect rect
);
Parameters
rect

The rectangle defining the area in which to draw.

Discussion

This function draws a frame around the inside of rect in the fill color of the current graphics context and using the kCGBlendModeCopy blend mode. The width is equal to 1.0 in the current coordinate system. Since the frame is drawn inside the rectangle, it is visible even if drawing is clipped to the rectangle. If the current graphics context is nil, this method does nothing.

Because this function does not draw directly on the line, but rather inside it, it uses the current fill color (not stroke color) when drawing.

You should call this function from the main thread of your application only.

Availability
Related Sample Code
Declared In
UIGraphics.h

UIRectFrameUsingBlendMode

Draws a frame around the inside of a rectangle using the specified blend mode.

void UIRectFrameUsingBlendMode (
   CGRect rect,
   CGBlendMode blendMode
);
Parameters
rect

The rectangle defining the area in which to draw.

blendMode

The blend mode to use during drawing.

Discussion

This function draws a frame around the inside of rect in the fill color of the current graphics context and using the specified blend mode. The width is equal to 1.0 in the current coordinate system. Since the frame is drawn inside the rectangle, it is visible even if drawing is clipped to the rectangle. If the current graphics context is nil, this method does nothing.

Because this function does not draw directly on the line, but rather inside it, it uses the current fill color (not stroke color) when drawing.

You should call this function from the main thread of your application only.

Availability
Declared In
UIGraphics.h

UISaveVideoAtPathToSavedPhotosAlbum

Adds the movie at the specified path to the user’s Saved Photos album.

void UISaveVideoAtPathToSavedPhotosAlbum (
   NSString  *videoPath,
   id        completionTarget,
   SEL       completionSelector,
   void      *contextInfo
);
Parameters
videoPath

The filesystem path to the movie file you want to save to the user’s Saved Photos album.

completionTarget

The object whose selector should be called after the movie has been written to the user’s device.

completionSelector

The method selector, of the target object, to call. This optional method should be of the form:

- (void) video: (NSString *) videoPath
    didFinishSavingWithError: (NSError *) error
    contextInfo: (void *) contextInfo;
contextInfo

An optional pointer to any context-specific data that you want passed to the completion selector.

Discussion

Before calling this function, you should call the UIVideoAtPathIsCompatibleWithSavedPhotosAlbum function to determine if it is possible to save videos to the Saved Photos album.

Availability
See Also
Declared In
UIImagePickerController.h

UIVideoAtPathIsCompatibleWithSavedPhotosAlbum

Returns a Boolean value indicating whether the specified video can be saved to user’s Saved Photos album.

BOOL UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(
   NSString *videoPath)
Parameters
videoPath

The filesystem path to the movie file you want to save.

Return Value

YES if the video can be saved to the photo album or NO if it cannot.

Discussion

Not all devices are able to play video files placed in the user’s Saved Photos album. So, before attempting to save videos to the user’s camera roll, you should call this function to ensure that saving the video is supported for the current device.

Availability
Declared In
UIImagePickerController.h


Last updated: 2009-08-04

Did this document help you? Yes It's good, but... Not helpful...