UIKit Function Reference
The UIKit framework defines a number of functions, many of them used in graphics and drawing operations.
-
This function is called in the
mainentry point to create the application object and the application delegate and set up the event cycle.Declaration
Swift
func UIApplicationMain(_argc: Int32, _argv: UnsafeMutablePointer<UnsafeMutablePointer<Int8>>, _principalClassName: String?, _delegateClassName: String?) -> Int32Parameters
argcThe count of arguments in
argv; this usually is the corresponding parameter tomain.argvA variable list of arguments; this usually is the corresponding parameter to
main.principalClassNameThe name of the
UIApplicationclass or subclass. If you specifynil,UIApplicationis assumed.delegateClassNameThe name of the class from which the application delegate is instantiated. If
principalClassNamedesignates a subclass ofUIApplication, you may designate the subclass as the delegate; the subclass instance receives the application-delegate messages. Specifynilif 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 exits an iOS application by pressing the Home button, the application moves to the background.
Discussion
This function instantiates the application object from the principal class 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.plistfile specifies a main nib file to be loaded, by including theNSMainNibFilekey 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 “Core App Objects” in App Programming Guide for iOS.
Availability
Available in iOS 2.0 and later.
-
Returns the data for the specified image in JPEG format.
Declaration
Parameters
imageThe original image data.
compressionQualityThe 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
A data object containing the JPEG data, or
nilif there was a problem generating the data. This function may returnnilif the image has no data or if the underlyingCGImageRefcontains data in an unsupported bitmap format.Discussion
If the image object’s underlying image data has been purged, calling this function forces that data to be reloaded into memory.
Availability
Available in iOS 2.0 and later.
-
Returns the data for the specified image in PNG format
Declaration
Parameters
imageThe original image data.
Return Value
A data object containing the PNG data, or
nilif there was a problem generating the data. This function may returnnilif the image has no data or if the underlyingCGImageRefcontains data in an unsupported bitmap format.Discussion
If the image object’s underlying image data has been purged, calling this function forces that data to be reloaded into memory.
Availability
Available in iOS 2.0 and later.
-
Adds the specified image to the user’s Camera Roll album.
Declaration
Swift
func UIImageWriteToSavedPhotosAlbum(_image: UIImage, _completionTarget: AnyObject?, _completionSelector: Selector, _contextInfo: UnsafeMutablePointer<Void>)Objective-C
void UIImageWriteToSavedPhotosAlbum ( UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo );Parameters
imageThe image to write to the Camera Roll album.
completionTargetOptionally, the object whose selector should be called after the image has been written to the Camera Roll album.
completionSelectorThe method selector, of the
completionTargetobject, to call. This optional method should conform to the following signature:- (void) image: (UIImage *) imagedidFinishSavingWithError: (NSError *) errorcontextInfo: (void *) contextInfo;
contextInfoAn optional pointer to any context-specific data that you want passed to the completion selector.
Discussion
When used with an image picker controller, you would typically call this function within your
imagePickerController:didFinishPickingMediaWithInfo:delegate method implementation.The use of the
completionTarget,completionSelector, andcontextInfoparameters is optional and necessary only if you want to be notified asynchronously when the function finishes writing the image to the user’s Camera Roll or Saved Photos album. If you do not want to be notified, passnilfor these parameters.When used on an iOS device without a camera, this method adds the image to the Saved Photos album rather than to the Camera Roll album.
Availability
Available in iOS 2.0 and later.
See Also
-
Adds the movie at the specified path to the user’s Camera Roll album.
Declaration
Swift
func UISaveVideoAtPathToSavedPhotosAlbum(_videoPath: String, _completionTarget: AnyObject?, _completionSelector: Selector, _contextInfo: UnsafeMutablePointer<Void>)Objective-C
void UISaveVideoAtPathToSavedPhotosAlbum ( NSString *videoPath, id completionTarget, SEL completionSelector, void *contextInfo );Parameters
videoPathThe filesystem path to the movie file you want to save to the Camera Roll album.
completionTargetOptionally, the object whose selector should be called after the movie has been written to the Camera Roll album.
completionSelectorThe method selector, of the
completionTargetobject, to call. This optional method should conform to the following signature:- (void) video: (NSString *) videoPathdidFinishSavingWithError: (NSError *) errorcontextInfo: (void *) contextInfo;
contextInfoAn optional pointer to any context-specific data that you want passed to the completion selector.
Discussion
When used with an image picker controller, you would typically call this function within your
imagePickerController:didFinishPickingMediaWithInfo:delegate method implementation.Before calling this function, call the
UIVideoAtPathIsCompatibleWithSavedPhotosAlbumfunction to determine if it is possible to save movies to the Camera Roll album. For a code example, refer to Camera Programming Topics for iOS.The use of the
completionTarget,completionSelector, andcontextInfoparameters is optional and necessary only if you want to be notified asynchronously when the function finishes writing the movie to the user’s Camera Roll or Saved Photos album. If you do not want to be notified, passnilfor these parameters.When used on an iOS device without a camera, this method adds the movie to the Saved Photos album rather than to the Camera Roll album.
Availability
Available in iOS 3.1 and later.
-
Returns a Boolean value indicating whether the specified video can be saved to user’s Camera Roll album.
Declaration
Objective-C
BOOL UIVideoAtPathIsCompatibleWithSavedPhotosAlbum ( NSString *videoPath );Parameters
videoPathThe filesystem path to the movie file you want to save.
Return Value
YEStrueif the video can be saved to the Camera Roll album orNOfalseif it cannot.Discussion
Not all devices are able to play video files placed in the user’s Camera Roll album. Before attempting to save a video, call this function and check its return value to ensure that saving the video is supported for the current device. For a code example, refer to Camera Programming Topics for iOS.
When used on an iOS device without a camera, this method indicates whether the specified movie can be saved to the Saved Photos album rather than to the Camera Roll album.
Availability
Available in iOS 3.1 and later.
See Also
-
Returns the current graphics context.
Declaration
Swift
func UIGraphicsGetCurrentContext() -> CGContext?Objective-C
CGContextRef UIGraphicsGetCurrentContext ( void );Return Value
The current graphics context.
Discussion
The current graphics context is
nilby default. Prior to calling itsdrawRect:method, view objects push a valid context onto the stack, making it current. If you are not using aUIViewobject to do your drawing, however, you must push a valid context onto the stack manually using theUIGraphicsPushContextfunction.This function may be called from any thread of your app.
Availability
Available in iOS 2.0 and later.
-
Makes the specified graphics context the current context.
Declaration
Swift
func UIGraphicsPushContext(_context: CGContext)Objective-C
void UIGraphicsPushContext ( CGContextRef context );Parameters
contextThe 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
UIGraphicsPopContextfunction.This function may be called from any thread of your app.
Availability
Available in iOS 2.0 and later.
See Also
-
Removes the current graphics context from the top of the stack, restoring the previous context.
Declaration
Swift
func UIGraphicsPopContext()Objective-C
void UIGraphicsPopContext ( void );Discussion
Use this function to balance calls to the
UIGraphicsPushContextfunction.This function may be called from any thread of your app.
Availability
Available in iOS 2.0 and later.
See Also
-
Creates a bitmap-based graphics context and makes it the current context.
Declaration
Swift
func UIGraphicsBeginImageContext(_size: CGSize)Objective-C
void UIGraphicsBeginImageContext ( CGSize size );Parameters
sizeThe size of the new bitmap context. This represents the size of the image returned by the
UIGraphicsGetImageFromCurrentImageContextfunction.Discussion
This function is equivalent to calling the
UIGraphicsBeginImageContextWithOptionsfunction with the opaque parameter set toNOfalseand a scale factor of1.0.This function may be called from any thread of your app.
Availability
Available in iOS 2.0 and later.
-
Creates a bitmap-based graphics context with the specified options.
Declaration
Parameters
sizeThe size (measured in points) of the new bitmap context. This represents the size of the image returned by the
UIGraphicsGetImageFromCurrentImageContextfunction. To get the size of the bitmap in pixels, you must multiply the width and height values by the value in thescaleparameter.opaqueA Boolean flag indicating whether the bitmap is opaque. If you know the bitmap is fully opaque, specify
YEStrueto ignore the alpha channel and optimize the bitmap’s storage. SpecifyingNOfalsemeans that the bitmap must include an alpha channel to handle any partially transparent pixels.scaleThe scale factor to apply to the bitmap. If you specify a value of
0.0, the scale factor is set to the scale factor of the device’s main screen.Discussion
You use this function to configure the drawing environment for rendering into a bitmap. The format for the bitmap is a ARGB 32-bit integer pixel format using host-byte order. If the opaque parameter is
YEStrue, the alpha channel is ignored and the bitmap is treated as fully opaque (kCGImageAlphaNoneSkipFirst|kCGBitmapByteOrder32Host). Otherwise, each pixel uses a premultipled ARGB format (kCGImageAlphaPremultipliedFirst|kCGBitmapByteOrder32Host).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 supplied scale factor is also applied to the coordinate system and resulting images. 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
UIGraphicsGetImageFromCurrentImageContextfunction to retrieve an image object based on the current contents of the context. When you are done modifying the context, you must call theUIGraphicsEndImageContextfunction to clean up the bitmap drawing environment and remove the graphics context from the top of the context stack. You should not use theUIGraphicsPopContextfunction 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
UIGraphicsGetCurrentContextfunction.This function may be called from any thread of your app.
Availability
Available in iOS 4.0 and later.
-
Returns an image based on the contents of the current bitmap-based graphics context.
Declaration
Swift
func UIGraphicsGetImageFromCurrentImageContext() -> UIImage!Objective-C
UIImage * UIGraphicsGetImageFromCurrentImageContext ( void );Return Value
A 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
nilor was not created by a call toUIGraphicsBeginImageContext, this function returnsnil.This function may be called from any thread of your app.
Availability
Available in iOS 2.0 and later.
See Also
-
Removes the current bitmap-based graphics context from the top of the stack.
Declaration
Swift
func UIGraphicsEndImageContext()Objective-C
void UIGraphicsEndImageContext ( void );Discussion
You use this function to clean up the drawing environment put in place by the
UIGraphicsBeginImageContextfunction and to remove the corresponding bitmap-based graphics context from the top of the stack. If the current context was not created using theUIGraphicsBeginImageContextfunction, this function does nothing.This function may be called from any thread of your app.
Availability
Available in iOS 2.0 and later.
See Also
-
Modifies the current clipping path by intersecting it with the specified rectangle.
Parameters
rectThe 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 function 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 state of the graphics context, call the
CGContextSaveGStatefunction before making your modifications. When you are ready to restore the original clipping region, you can then use theCGContextRestoreGStatefunction to restore the previous graphics state.This function may be called from any thread of your app.
Availability
Available in iOS 2.0 and later.
-
Fills the specified rectangle with the current color.
Parameters
rectThe rectangle defining the area in which to draw.
Discussion
Fills the specified rectangle using the fill color of the current graphics context and the
kCGBlendModeCopyblend mode.This function may be called from any thread of your app.
Availability
Available in iOS 2.0 and later.
-
Fills a rectangle with the current fill color using the specified blend mode.
Declaration
Swift
func UIRectFillUsingBlendMode(_rect: CGRect, _blendMode: CGBlendMode)Objective-C
void UIRectFillUsingBlendMode ( CGRect rect, CGBlendMode blendMode );Parameters
rectThe rectangle defining the area in which to draw.
blendModeThe 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 function does nothing.This function may be called from any thread of your app.
Availability
Available in iOS 2.0 and later.
-
Draws a frame around the inside of the specified rectangle.
Parameters
rectThe rectangle defining the area in which to draw.
Discussion
This function draws a frame around the inside of
rectin the stroke color of the current graphics context and using thekCGBlendModeCopyblend mode. The width is equal to 1.0 in the current coordinate system. Because the frame is drawn inside the rectangle, it is visible even if drawing is clipped to the rectangle. If the current graphics context isnil, this function does nothing.This function may be called from any thread of your app.
Availability
Available in iOS 2.0 and later.
-
Draws a frame around the inside of a rectangle using the specified blend mode.
Declaration
Swift
func UIRectFrameUsingBlendMode(_rect: CGRect, _blendMode: CGBlendMode)Objective-C
void UIRectFrameUsingBlendMode ( CGRect rect, CGBlendMode blendMode );Parameters
rectThe rectangle defining the area in which to draw.
blendModeThe 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 function 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.
This function may be called from any thread of your app.
Availability
Available in iOS 2.0 and later.
-
Creates a dictionary wherein the keys are string representations of the corresponding values’ variable names.
Declaration
Objective-C
#define NSDictionaryOfVariableBindings(...) _NSDictionaryOfVariableBindings(@"" # __VA_ARGS__, __VA_ARGS__, nil)Discussion
This macro is particularly useful when creating Autolayout constraints—see Auto Layout Guide. For example, the following code:
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(button1, button2);
creates the dictionary
{ @"button1" = button1, @"button2 = button2 }.Availability
Available in iOS 6.0 and later.
-
Creates a PDF-based graphics context that targets the specified mutable data object.
Declaration
Swift
func UIGraphicsBeginPDFContextToData(_data: NSMutableData, _bounds: CGRect, _documentInfo: [NSObject : AnyObject]?)Objective-C
void UIGraphicsBeginPDFContextToData ( NSMutableData *data, CGRect bounds, NSDictionary *documentInfo );Parameters
dataThe data object to receive the PDF output data.
boundsA rectangle that specifies the default size and location of PDF pages. (This value is used as the default media box for each new page.) The origin of the rectangle should typically be (0, 0). Specifying an empty rectangle (
CGRectZero) sets the default page size to 8.5 by 11 inches (612 by 792 points).documentInfoA dictionary that specifies additional information to be associated with the PDF file. You can use these keys to specify additional metadata and security information for the PDF, such as the author of the PDF or the password for accessing it. The keys in this dictionary are the same keys you pass to the
CGPDFContextCreatefunction and are described in the Auxiliary Dictionary Keys section of CGPDFContext Reference. The dictionary is retained by the new context, so on return you may safely release it.Specify
nilif you do not want to associate any additional information with the PDF document.Discussion
After creating the graphics context, this function makes it the current drawing context. Any subsequent drawing commands are therefore captured and turned into PDF data. When you are done drawing, you must call the
UIGraphicsEndPDFContextfunction to close the PDF graphics context.You can use all of the same drawing routines that you would normally use to draw the contents of your application. The graphics context converts all drawing commands into PDF drawing commands automatically. However, before you issue any drawing commands to a PDF context, you must start a new page by calling the
UIGraphicsBeginPDFPageorUIGraphicsBeginPDFPageWithInfofunction. You can also use these functions to define additional pages later.After creating it, you can get the PDF context using the
UIGraphicsGetCurrentContextfunction.Availability
Available in iOS 3.2 and later.
See Also
-
Creates a PDF-based graphics context that targets a file at the specified path.
Declaration
Swift
func UIGraphicsBeginPDFContextToFile(_path: String, _bounds: CGRect, _documentInfo: [NSObject : AnyObject]?) -> BoolObjective-C
BOOL UIGraphicsBeginPDFContextToFile ( NSString *path, CGRect bounds, NSDictionary *documentInfo );Parameters
pathA POSIX-style path string identifying the location of the resulting PDF file. The specified path may be relative or a full path name. If a file does not exist at the specified path, one is created; otherwise, the contents of any existing file are deleted. The directories in the path must exist.
boundsA rectangle that specifies the default size and location of PDF pages. (This value is used as the default media box for each new page.) The origin of the rectangle should typically be (0, 0). Specifying an empty rectangle (
CGRectZero) sets the default page size to 8.5 by 11 inches (612 by 792 points).documentInfoA dictionary that specifies additional information to be associated with the PDF file. You can use these keys to specify additional metadata and security information for the PDF, such as the author of the PDF or the password for accessing it. The keys in this dictionary are the same keys you pass to the
CGPDFContextCreatefunction and are described in the Auxiliary Dictionary Keys section of CGPDFContext Reference. The dictionary is retained by the new context, so on return you may safely release it.Specify
nilif you do not want to associate any additional information with the PDF document.Return Value
YEStrueif the PDF context was created successfully orNOfalseif it was not.Discussion
After creating the graphics context, this function makes it the current drawing context. Any subsequent drawing commands are therefore captured and turned into PDF data. When you are done drawing, you must call the
UIGraphicsEndPDFContextfunction to close the PDF graphics context.You can use all of the same drawing routines that you would normally use to draw the contents of your application. However, before you issue any drawing commands to a PDF context, you must start a new page by calling the
UIGraphicsBeginPDFPageorUIGraphicsBeginPDFPageWithInfofunction. You can also use these functions to define additional pages later.After creating it, you can get the PDF context using the
UIGraphicsGetCurrentContextfunction.Availability
Available in iOS 3.2 and later.
-
Closes a PDF graphics context and pops it from the current context stack.
Declaration
Swift
func UIGraphicsEndPDFContext()Objective-C
void UIGraphicsEndPDFContext ( void );Discussion
You must call this function after you finish drawing to a PDF graphics context. This function closes the current open page and removes the PDF context from the graphics context stack. It also releases the
CGContextRefassociated with the PDF context. If the current graphics context is not a PDF context, this function does nothing.Availability
Available in iOS 3.2 and later.
-
Marks the beginning of a new page in a PDF context and configures it using default values.
Declaration
Swift
func UIGraphicsBeginPDFPage()Objective-C
void UIGraphicsBeginPDFPage ( void );Discussion
This function ends any previous page before beginning a new one. It sets the media box of the new page to the rectangle you specified when you created the PDF context.
If the current graphics context is not a PDF context, this function does nothing.
You must call this function or the
UIGraphicsBeginPDFPageWithInfofunction before you issue any drawing commands.Availability
Available in iOS 3.2 and later.
-
Marks the beginning of a new page in a PDF context and configures it using the specified values.
Declaration
Objective-C
void UIGraphicsBeginPDFPageWithInfo ( CGRect bounds, NSDictionary *pageInfo );Parameters
boundsA rectangle that specifies the size and location of the new PDF page. This rectangle corresponds to the media box rectangle for the page.
pageInfoA dictionary that specifies additional page-related information, such as the boxes that define different parts of the page. For a list of keys you can include in this dictionary, see Box Dictionary Keys in CGPDFContext Reference. The dictionary is retained by the new page, so you may release it after this function returns.
Specify
nilif you do not want to associate any additional information with the page.Discussion
This function ends any previous page before beginning a new one. It sets the media box of the new page to the value in the
kCGPDFContextMediaBoxkey of thepageInfodictionary, or to the value in theboundsparameter if the dictionary does not contain the key.If the current graphics context is not a PDF context, this function does nothing.
You must call this function or the
UIGraphicsBeginPDFPageWithInfofunction before you issue any drawing commands.Availability
Available in iOS 3.2 and later.
-
Returns the current page bounds.
Declaration
Swift
func UIGraphicsGetPDFContextBounds() -> CGRectObjective-C
CGRect UIGraphicsGetPDFContextBounds ( void );Return Value
The current page bounds associated with the PDF context or
CGRectZeroif the current context is not a PDF context.Discussion
If a page has not yet been started, this function returns the default media box you specified when you created the PDF context; otherwise, it returns the page bounds for the current page.
Availability
Available in iOS 3.2 and later.
-
Creates a jump destination in the current page.
Declaration
Parameters
nameThe name of the destination point. The name you assign is local to the PDF document and is what you use when creating links to this destination.
pointA point on the current page of the PDF context.
Discussion
This function marks the specified point in the current page as the destination of a jump. When the user taps a link that takes them to this jump destination, the PDF document scrolls until the specified point is visible.
If the current graphics context is not a PDF context, this function does nothing.
For information on how to create links to this destination, see the
UIGraphicsSetPDFContextDestinationForRectfunction.Availability
Available in iOS 3.2 and later.
-
Links a rectangle on the current page to the specified jump destination.
Declaration
Parameters
nameA named destination in the PDF document. This is the same name you used when creating the jump destination using the
UIGraphicsAddPDFContextDestinationAtPointfunction.rectA rectangle on the current page of the PDF context.
Discussion
You use this function to create live links within a PDF document. Tapping the specified rectangle in the PDF document causes the document to display the contents at the associated jump destination.
If the current graphics context is not a PDF context, this function does nothing.
Availability
Available in iOS 3.2 and later.
-
Links a rectangle on the current page to the specified URL.
Declaration
Parameters
urlThe URL to open.
rectA rectangle on the current page of the PDF context.
Discussion
You use this function to create external links within a PDF document. If the URL you specify is a type handled by a different application, tapping the rectangle opens that application.
If the current graphics context is not a PDF context, this function does nothing.
Availability
Available in iOS 3.2 and later.
-
Returns a Core Graphics affine transform structure corresponding to the data in a given string.
Declaration
Swift
func CGAffineTransformFromString(_string: String) -> CGAffineTransformObjective-C
CGAffineTransform CGAffineTransformFromString ( NSString *string );Parameters
stringA string 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
CGAffineTransformdata 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 separated 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
NSStringFromCGAffineTransformfunction.Availability
Available in iOS 2.0 and later.
See Also
-
Returns a Core Graphics point structure corresponding to the data in a given string.
Declaration
Parameters
stringA string 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 separated 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
NSStringFromCGPointfunction.Availability
Available in iOS 2.0 and later.
See Also
-
Returns a Core Graphics rectangle structure corresponding to the data in a given string.
Declaration
Parameters
stringA string 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 separated 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
NSStringFromCGRectfunction.Availability
Available in iOS 2.0 and later.
See Also
-
Returns a Core Graphics size structure corresponding to the data in a given string.
Declaration
Parameters
stringA string 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 separated 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
NSStringFromCGSizefunction.Availability
Available in iOS 2.0 and later.
See Also
-
Returns a Core Graphics vector corresponding to the data in a given string.
Declaration
Parameters
stringA string whose contents are of the form “{dx, dy}”, where dx is the x-coordinate of the vector and dy is the y-coordinate. The dx and dy 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 separated with a comma.
Return Value
A Core Graphics structure that represents a two-dimensional vector. If the string is not well-formed, the function returns a vector whose dx and dy values are
0.Discussion
In general, you should use this function only to convert strings that were previously created using the
NSStringFromCGVectorfunction.Availability
Available in iOS 8.0 and later.
See Also
-
Returns a string formatted to contain the data from an affine transform.
Declaration
Swift
func NSStringFromCGAffineTransform(_transform: CGAffineTransform) -> StringObjective-C
NSString * NSStringFromCGAffineTransform ( CGAffineTransform transform );Parameters
transformA Core Graphics affine transform structure.
Return Value
A string that corresponds to
transform. SeeCGAffineTransformFromStringfor a discussion of the string format.Availability
Available in iOS 2.0 and later.
See Also
-
Returns a string formatted to contain the data from a point.
Declaration
Parameters
pointA Core Graphics structure representing a point.
Return Value
A string that corresponds to
point. SeeCGPointFromStringfor a discussion of the string format.Availability
Available in iOS 2.0 and later.
See Also
-
Returns a string formatted to contain the data from a rectangle.
Declaration
Parameters
rectA Core Graphics structure representing a rectangle.
Return Value
A string that corresponds to
rect. SeeCGRectFromStringfor a discussion of the string format.Availability
Available in iOS 2.0 and later.
See Also
-
Returns a string formatted to contain the data from a size data structure.
Declaration
Parameters
sizeA Core Graphics structure representing a size.
Return Value
A string that corresponds to
size. SeeCGSizeFromStringfor a discussion of the string format.Availability
Available in iOS 2.0 and later.
See Also
-
Returns a string formatted to contain the data from a vector data structure.
Declaration
Parameters
vectorA Core Graphics structure representing a two-dimensional vector.
Return Value
A string that corresponds to
vector. SeeCGVectorFromStringfor a discussion of the string format.Availability
Available in iOS 8.0 and later.
See Also
-
Returns a string formatted to contain the data from an edge insets structure.
Declaration
Swift
func NSStringFromUIEdgeInsets(_insets: UIEdgeInsets) -> StringObjective-C
NSString * NSStringFromUIEdgeInsets ( UIEdgeInsets insets );Parameters
insetsA UIKit edge insets data structure.
Return Value
A string that corresponds to
insets. SeeUIEdgeInsetsFromStringfor a discussion of the string format.Availability
Available in iOS 2.0 and later.
See Also
-
Returns a string formatted to contain the data from an offset structure.
Declaration
Parameters
offsetA UIKit offset data structure.
Return Value
A string that corresponds to
offset.Availability
Available in iOS 5.0 and later.
See Also
-
Returns a UIKit edge insets structure corresponding to the data in a given string.
Declaration
Swift
func UIEdgeInsetsFromString(_string: String) -> UIEdgeInsetsObjective-C
UIEdgeInsets UIEdgeInsetsFromString ( NSString *string );Parameters
stringA string whose contents are of the form “{top, left, bottom, right}”, where top, left, bottom, right are the floating-point component values of the
UIEdgeInsetsstructure. An example of a valid string is @”{3.0,8.0,3.0,5.0}”. The string is not localized, so items are always separated 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
NSStringFromUIEdgeInsetsfunction.Availability
Available in iOS 2.0 and later.
See Also
-
Returns a UIKit offset structure corresponding to the data in a given string.
Declaration
Parameters
stringA string containing a representation of an offset.
Return Value
An edge insets data structure. If the string is not well-formed, the function returns
UIOffsetZero.Discussion
In general, you should use this function only to convert strings that were previously created using the
NSStringFromUIOffsetfunction.Availability
Available in iOS 5.0 and later.
-
Creates an edge inset for a button or view.
Declaration
Swift
func UIEdgeInsetsMake(_top: CGFloat, _left: CGFloat, _bottom: CGFloat, _right: CGFloat) -> UIEdgeInsetsObjective-C
UIEdgeInsets UIEdgeInsetsMake ( CGFloat top, CGFloat left, CGFloat bottom, CGFloat right );Parameters
topThe inset at the top of an object.
leftThe inset on the left of an object
bottomThe inset on the bottom of an object.
rightThe 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
Available in iOS 2.0 and later.
See Also
-
Compares two edge insets to determine if they are the same.
Declaration
Swift
func UIEdgeInsetsEqualToEdgeInsets(_insets1: UIEdgeInsets, _insets2: UIEdgeInsets) -> BoolObjective-C
BOOL UIEdgeInsetsEqualToEdgeInsets ( UIEdgeInsets insets1, UIEdgeInsets insets2 );Parameters
insets1An edge inset to compare with
insets2.insets2An edge inset to compare with
insets1.Return Value
YEStrueif the edge insets are the same; otherwise,NOfalse.Availability
Available in iOS 2.0 and later.
See Also
-
Adjusts a rectangle by the given edge insets.
Declaration
Swift
func UIEdgeInsetsInsetRect(_rect: CGRect, _insets: UIEdgeInsets) -> CGRectObjective-C
CGRect UIEdgeInsetsInsetRect ( CGRect rect, UIEdgeInsets insets );Parameters
rectThe rectangle to be adjusted.
insetsThe edge insets to be applied to the adjustment.
Return Value
A rectangle that is adjusted by the
UIEdgeInsetsstructure passed in insets.Discussion
This inline function increments the origin of
rectand decrements the size ofrectby applying the appropriate member values of theUIEdgeInsetsstructure.Availability
Available in iOS 2.0 and later.
See Also
-
Returns an offset structure from the given components.
Declaration
Swift
func UIOffsetMake(_horizontal: CGFloat, _vertical: CGFloat) -> UIOffsetParameters
horizontalThe horizontal offset.
verticalThe vertical offset.
Return Value
An offset structure with offsets
horizontalandvertical.Availability
Available in iOS 5.0 and later.
-
Returns a Boolean value that indicates whether two offsets are equal.
Declaration
Parameters
offset1The offset to compare with
offset2.offset2The offset to compare with
offset1.Return Value
YEStrueifoffset1andoffset2are equal, otherwiseNOfalse.Availability
Available in iOS 5.0 and later.
-
Returns a new float range structure from the given components.
Declaration
Swift
func UIFloatRangeMake(_minimum: CGFloat, _maximum: CGFloat) -> UIFloatRangeParameters
minimumThe minimum range value, which is typically less than or equal to
0.maximumThe maximum range value, which is typically greater than or equal to
0.Discussion
Float ranges are used in
UIAttachmentBehaviorobjects to define the maximum range of translation or rotation for animations.Availability
Available in iOS 9.0 and later.
-
Returns a Boolean indicating whether the specified float range is infinitely large.
Declaration
Swift
func UIFloatRangeIsInfinite(_range: UIFloatRange) -> BoolObjective-C
BOOL UIFloatRangeIsInfinite ( UIFloatRange range );Parameters
rangeThe range value to check.
Availability
Available in iOS 9.0 and later.
-
Returns a Boolean indicating whether two float ranges are equivalent.
Declaration
Swift
func UIFloatRangeIsEqualToRange(_range: UIFloatRange, _otherRange: UIFloatRange) -> BoolObjective-C
BOOL UIFloatRangeIsEqualToRange ( UIFloatRange range, UIFloatRange otherRange );Parameters
rangeThe first range to compare.
otherRangeThe second range to compare.
Discussion
Two ranges are considered equal when their minimum values are the same and their maximum values are the same. In practice, the minimum and maximum values do not have to be exactly equal, but the difference between each pair of values must be less than
FLT_EPSILON.Availability
Available in iOS 9.0 and later.
-
Returns a Boolean value indicating whether the user interface is currently presented in a portrait orientation.
Declaration
Swift
func UIInterfaceOrientationIsPortrait(_orientation: UIInterfaceOrientation) -> BoolObjective-C
BOOL UIInterfaceOrientationIsPortrait ( UIInterfaceOrientation orientation );Parameters
orientationSpecify the orientation constant to check.
Return Value
Returns
YEStrueif the interface orientation is portrait, otherwise returnsNOfalse.Discussion
The interface orientation can be different than the device orientation. You typically call this function in your view controller code to check the current orientation.
Availability
Available in iOS 8.3 and later.
-
Returns a Boolean value indicating whether the user interface is currently presented in a landscape orientation.
Declaration
Swift
func UIInterfaceOrientationIsLandscape(_orientation: UIInterfaceOrientation) -> BoolObjective-C
BOOL UIInterfaceOrientationIsLandscape ( UIInterfaceOrientation orientation );Parameters
orientationSpecify the orientation constant to check.
Return Value
Returns
YEStrueif the interface orientation is landscape, otherwise returnsNOfalse.Discussion
The interface orientation can be different than the device orientation. You typically call this function in your view controller code to check the current orientation.
Availability
Available in iOS 8.3 and later.
-
Returns a Boolean value indicating whether the device is in a portrait orientation.
Declaration
Swift
func UIDeviceOrientationIsPortrait(_orientation: UIDeviceOrientation) -> BoolObjective-C
BOOL UIDeviceOrientationIsPortrait ( UIDeviceOrientation orientation );Parameters
orientationSpecify the value of the
orientationproperty of theUIDeviceclass.Return Value
Returns
YEStrueif the device orientation is portrait, otherwise returnsNOfalse.Availability
Available in iOS 8.3 and later.
-
Returns a Boolean value indicating whether the device is in a landscape orientation.
Declaration
Swift
func UIDeviceOrientationIsLandscape(_orientation: UIDeviceOrientation) -> BoolObjective-C
BOOL UIDeviceOrientationIsLandscape ( UIDeviceOrientation orientation );Parameters
orientationSpecify the value of the
orientationproperty of theUIDeviceclass.Return Value
Returns
YEStrueif the device orientation is landscape, otherwise returnsNOfalse.Availability
Available in iOS 8.3 and later.
-
Returns the interface idiom supported by the current device (recommended for apps that run in versions of iOS earlier than 3.2).
Declaration
Swift
func UI_USER_INTERFACE_IDIOM() -> UIUserInterfaceIdiomObjective-C
UIUserInterfaceIdiom UI_USER_INTERFACE_IDIOM ( void );Return Value
UIUserInterfaceIdiomPhoneif the device is an iPhone or iPod touch orUIUserInterfaceIdiomPadif the device is an iPad.Discussion
If your app runs in iOS 3.2 and later, use
userInterfaceIdiominstead.Availability
Available in iOS 8.3 and later.
-
Posts a notification to assistive applications.
Declaration
Swift
func UIAccessibilityPostNotification(_notification: UIAccessibilityNotifications, _argument: AnyObject?)Objective-C
void UIAccessibilityPostNotification ( UIAccessibilityNotifications notification, id argument );Parameters
notificationThe notification to post (see “Notifications” in UIAccessibility Protocol Reference for a list of notifications).
argumentThe argument specified by the notification. Pass
nilunless 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
Available in iOS 3.0 and later.
-
Converts the specified rectangle from view coordinates to screen coordinates.
Declaration
Parameters
rectA rectangle specified in the coordinate system of the specified
view.viewThe view that contains the specified rectangle. This parameter must not be
nil.Return Value
The rectangle in screen coordinates.
Discussion
Use this function to convert accessibility frame rectangles to screen coordinates.
Availability
Available in iOS 7.0 and later.
-
Converts the specified path object to screen coordinates and returns a new path object with the results.
Declaration
Swift
func UIAccessibilityConvertPathToScreenCoordinates(_path: UIBezierPath, _view: UIView) -> UIBezierPathObjective-C
UIBezierPath * UIAccessibilityConvertPathToScreenCoordinates ( UIBezierPath *path, UIView *view );Parameters
pathThe path object that you want to convert. The coordinate values used to create this path object should be relative to the coordinate system of the specified
view. This parameter must not benil.viewThe view whose coordinate system was used to define the path. This parameter must not be
nil.Return Value
A new path object that has the same shape as
pathbut whose points are specified in screen coordinates.Discussion
This function adjusts the points of the path you provide to values that the accessibility system can use. You can use it to convert path objects in use by your app’s user interface before handing them to the accessibility system.
Availability
Available in iOS 7.0 and later.
-
Warns users that application-specific gestures conflict with the system-defined Zoom accessibility gestures.
Declaration
Swift
func UIAccessibilityRegisterGestureConflictWithZoom()Objective-C
void UIAccessibilityRegisterGestureConflictWithZoom ( void );Discussion
Use this function if your application uses multi-finger gestures that conflict with the gestures used by system Zoom (that is, three-finger gestures). When this is the case, the user is presented with the choice of turning off Zoom or continuing.
Availability
Available in iOS 5.0 and later.
-
Transitions the app to or from Single App mode asynchronously.
Declaration
Swift
func UIAccessibilityRequestGuidedAccessSession(_enable: Bool, _completionHandler: (Bool) -> Void)Objective-C
void UIAccessibilityRequestGuidedAccessSession ( BOOL enable, void (^completionHandler)(BOOL didSucceed) );Parameters
enableSpecify
YEStrueto put the device into Single App mode for this app orNOfalseto exit Single App mode.completionHandlerThe block that notifies your app of the success or failure of the operation. This block takes the following parameter:
didSucceedIf
YEStrue, the app transitioned to or from Single App mode successfully. IfNOfalse, the app or device is not eligible for Single App mode or there was some other error.Discussion
You can use this method to lock your app into Single App mode and to release it from that mode later. For example, a test-taking app might enter this mode at the beginning of a test and exit it when the user completes the test. Entering Single App mode is supported only for devices that are supervised using Mobile Device Management (MDM), and the app itself must be enabled for this mode by MDM. You must balance each call to enter Single App mode with a call to exit that mode.
Because entering or exiting Single App mode might take some time, this method executes asynchronously and notifies you of the results using the
completionHandlerblock.Availability
Available in iOS 7.0 and later.
See Also
-
Notifies the system that the app’s focus has changed to a new location.
Declaration
Swift
func UIAccessibilityZoomFocusChanged(_type: UIAccessibilityZoomType, _frame: CGRect, _view: UIView)Objective-C
void UIAccessibilityZoomFocusChanged ( UIAccessibilityZoomType type, CGRect frame, UIView *view );Parameters
typeA
Introductionconstant that identifies the type of Zoom.frameThe frame that is currently zoomed, in screen coordinates.
viewThe view that contains the zoomed frame.
Availability
Available in iOS 5.0 and later.
-
Returns a Boolean value indicating whether bold text is enabled.
Declaration
Swift
func UIAccessibilityIsBoldTextEnabled() -> BoolObjective-C
BOOL UIAccessibilityIsBoldTextEnabled ( void );Return Value
YEStrueif the user has enabled Bold Text in Settings; otherwise,NOfalse.Availability
Available in iOS 8.0 and later.
-
Returns a Boolean value indicating whether closed captioning is enabled.
Declaration
Swift
func UIAccessibilityIsClosedCaptioningEnabled() -> BoolObjective-C
BOOL UIAccessibilityIsClosedCaptioningEnabled ( void );Return Value
YEStrueif the user has enabled closed captioning in Settings; otherwise,NOfalse.Availability
Available in iOS 5.0 and later.
-
Returns a Boolean value indicating whether darken colors is enabled.
Declaration
Swift
func UIAccessibilityDarkerSystemColorsEnabled() -> BoolObjective-C
BOOL UIAccessibilityDarkerSystemColorsEnabled ( void );Return Value
YEStrueif the user has enabled Darken Colors in Settings; otherwise,NOfalse.Availability
Available in iOS 8.0 and later.
-
Returns a Boolean value indicating whether grayscale is enabled.
Declaration
Swift
func UIAccessibilityIsGrayscaleEnabled() -> BoolObjective-C
BOOL UIAccessibilityIsGrayscaleEnabled ( void );Return Value
YEStrueif the user has enabled Grayscale in Settings; otherwise,NOfalse.Availability
Available in iOS 8.0 and later.
-
Returns a Boolean value indicating whether Guided Access is enabled.
Declaration
Swift
func UIAccessibilityIsGuidedAccessEnabled() -> BoolObjective-C
BOOL UIAccessibilityIsGuidedAccessEnabled ( void );Return Value
YEStrueif the user has enabled Guided Access in Settings; otherwise,NOfalse.Availability
Available in iOS 6.0 and later.
-
Returns a Boolean value indicating whether inverted colors is enabled.
Declaration
Swift
func UIAccessibilityIsInvertColorsEnabled() -> BoolObjective-C
BOOL UIAccessibilityIsInvertColorsEnabled ( void );Return Value
YEStrueif the user has enabled inverted colors in Settings; otherwise,NOfalse.Availability
Available in iOS 6.0 and later.
-
Returns a Boolean value indicating whether system audio is set to mono.
Declaration
Swift
func UIAccessibilityIsMonoAudioEnabled() -> BoolObjective-C
BOOL UIAccessibilityIsMonoAudioEnabled ( void );Return Value
YEStrueif mono audio is currently enabled; otherwise,NOfalse.Availability
Available in iOS 5.0 and later.
-
Returns a Boolean value indicating whether reduce motion is enabled.
Declaration
Swift
func UIAccessibilityIsReduceMotionEnabled() -> BoolObjective-C
BOOL UIAccessibilityIsReduceMotionEnabled ( void );Return Value
YEStrueif the user has enabled Reduce Motion in Settings; otherwise,NOfalse.Availability
Available in iOS 8.0 and later.
-
Returns a Boolean value indicating whether reduce transparency is enabled.
Declaration
Swift
func UIAccessibilityIsReduceTransparencyEnabled() -> BoolObjective-C
BOOL UIAccessibilityIsReduceTransparencyEnabled ( void );Return Value
YEStrueif the user has enabled Reduce Transparency in Settings; otherwise,NOfalse.Availability
Available in iOS 8.0 and later.
-
Returns a Boolean value indicating whether speaking the screen is enabled.
Declaration
Swift
func UIAccessibilityIsSpeakScreenEnabled() -> BoolObjective-C
BOOL UIAccessibilityIsSpeakScreenEnabled ( void );Return Value
YEStrueif the user has enabled Speak Screen in Settings; otherwise,NOfalse.Availability
Available in iOS 8.0 and later.
-
Returns a Boolean value indicating whether speaking the selection is enabled.
Declaration
Swift
func UIAccessibilityIsSpeakSelectionEnabled() -> BoolObjective-C
BOOL UIAccessibilityIsSpeakSelectionEnabled ( void );Return Value
YEStrueif the user has enabled Speak Selection in Settings; otherwise,NOfalse.Availability
Available in iOS 8.0 and later.
-
Returns a Boolean value indicating whether Switch Control is enabled.
Declaration
Swift
func UIAccessibilityIsSwitchControlRunning() -> BoolObjective-C
BOOL UIAccessibilityIsSwitchControlRunning ( void );Return Value
YEStrueif the user has enabled Switch Control in Settings; otherwise,NOfalse.Availability
Available in iOS 8.0 and later.
-
Returns a Boolean value indicating whether VoiceOver is running.
Declaration
Swift
func UIAccessibilityIsVoiceOverRunning() -> BoolObjective-C
BOOL UIAccessibilityIsVoiceOverRunning ( void );Return Value
YEStrueif VoiceOver is currently running; otherwise,NOfalse.Discussion
You can use this function to customize your application’s UI specifically for VoiceOver users. For example, you might want UI elements that usually disappear quickly to persist onscreen for VoiceOver users. Note that you can also listen for the
UIAccessibilityVoiceOverStatusChangednotification to find out when VoiceOver starts and stops.Availability
Available in iOS 4.0 and later.
-
Converts a UIKit text alignment constant value to the matching constant value used by Core Text.
Declaration
Swift
func NSTextAlignmentToCTTextAlignment(_nsTextAlignment: NSTextAlignment) -> CTTextAlignmentObjective-C
CTTextAlignment NSTextAlignmentToCTTextAlignment ( NSTextAlignment nsTextAlignment );Parameters
nsTextAlignmentThe UIKit text alignment constant you want to convert.
Return Value
The Core Text alignment that corresponds to the value specified in
nsTextAlignment.Discussion
Use this function when you need to map between the UIKit and Core Text constants for text alignment.
Availability
Available in iOS 6.0 and later.
-
Converts a Core Text alignment constant value to the matching constant value used by UIKit.
Declaration
Swift
func NSTextAlignmentFromCTTextAlignment(_ctTextAlignment: CTTextAlignment) -> NSTextAlignmentObjective-C
NSTextAlignment NSTextAlignmentFromCTTextAlignment ( CTTextAlignment ctTextAlignment );Parameters
ctTextAlignmentThe Core text alignment constant you want to convert.
Return Value
The UIKit text alignment that corresponds to the value specified in
ctTextAlignment.Discussion
Use this function when you need to map between the Core Text and UIKit constants for text alignment.
Availability
Available in iOS 6.0 and later.
-
Returns the restriction state for the specified guided access restriction.
Declaration
Swift
func UIGuidedAccessRestrictionStateForIdentifier(_restrictionIdentifier: String) -> UIGuidedAccessRestrictionStateObjective-C
UIGuidedAccessRestrictionState UIGuidedAccessRestrictionStateForIdentifier ( NSString *restrictionIdentifier );Parameters
restrictionIdentifierThe string that uniquely identifies the guided access restriction.
Return Value
The current state of the guided access restriction. The initial state of all restrictions is
UIGuidedAccessRestrictionStateAllow.Availability
Available in iOS 7.0 and later.
Copyright © 2015 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2015-10-21
