Application Launch
UIApplicationMain
int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName);
应用程序启动入口。
principalClassName:
UIApplication类或者其子类的名字。如果为设置nil,info.plist中的NSPrincipalClass字段的值将被采用。如果没有指定NSPrincipalClass字段,就将使用UIApplication类,代理类将会被实例化。
delegateClassName:
被实例化的应用代理类名。如果delegateClassName指定了一个UIApplication的子类,那么指定这个子类为代理;子类的实例会收到应用代理的消息。如果从应用程序的主nib文件众加载代理对象,那么就设置为nil。
尽管这个方法声明了返回值,但是它永远不会返回。
Image Manipulation
UIImageJPEGRepresentation
NSData *UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality);
返回指定图像JPEGG格式的数据。
image:
原始图片数据。
compressionQuality:
返回的JEPG图片的质量,这个值是从0.0-1.0. 0.0表示最大程度的压缩(质量最低的)当然1.0表示最低压缩(也就是质量最高的)。
如果图片不包含CGImageRef或者不合法的位图格式就返回nil。
UIImagePNGRepresentation
NSData *UIImagePNGRepresentation(UIImage *image);
返回指定图像PNG格式的数据。
同 UIImageJPEGRepresentation 。
Image and Movie Saving
UIImageWriteToSavedPhotosAlbum
void UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);
添加指定图片到用户相册。
UISaveVideoAtPathToSavedPhotosAlbum
void UISaveVideoAtPathToSavedPhotosAlbum(NSString *videoPath, id completionTarget, SEL completionSelector, void *contextInfo) NS_AVAILABLE_IOS(3_1);
添加指定视频到用户相册。
UIVideoAtPathIsCompatibleWithSavedPhotosAlbum
BOOL UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(NSString *videoPath) NS_AVAILABLE_IOS(3_1);
Creating a Dictionary
#define NSDictionaryOfVariableBindings(...) _NSDictionaryOfVariableBindings(@"" # __VA_ARGS__, __VA_ARGS__, nil)
创建一个字典,这个字典中与value值相关联的key值为字符串。
当创建自动布局约束的时候这个宏是特别有用的。
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(button1, button2);
creates the dictionary { @"button1" = button1, @"button2 = button2 }.
NSDictionaryOfVariableBindings(v1, v2, v3) 与 [NSDictionary dictionaryWithObjectsAndKeys:v1, @"v1", v2, @"v2", v3, @"v3", nil]; 是一样的。
Graphics
UIGraphicsGetCurrentContext
CGContextRef UIGraphicsGetCurrentContext(void);
返回当前图形上下文。
UIGraphicsPushContext
void UIGraphicsPushContext(CGContextRef context);
把指定的图形上下文作为当前图形上下文。
在iOS4以后的系统中,你可以在你的应用程序的任何线程中调用这个方法。
UIGraphicsPopContext
void UIGraphicsPopContext(void);
把当前的图形上下文从栈顶移除,并且回复上一个图形上下文。
使用这个方法时必须和 UIGraphicsPushContext 这个方法配对使用。
在iOS4以后的系统中,你可以在你的应用程序的任何线程中调用这个方法。
UIGraphicsBeginImageContext
void UIGraphicsBeginImageContext(CGSize size);
创建一个基于位图的图形上下文并且把它作为当前的图形上下文。
这个方法相当于调用 UIGraphicsBeginImageContextWithOptions 这个方法,并且把不透明参数设置为NO和把放大缩小参数设置为1.0.
UIGraphicsBeginImageContextWithOptions
void UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale) NS_AVAILABLE_IOS(4_0);
创建一个带指定设置的基于位图的图形上下文。
size:
UIGraphicsGetImageFromCurrentImageContext
UIImage* UIGraphicsGetImageFromCurrentImageContext(void);
获得一个基于位图的图形上下文的内容的图片。
UIGraphicsEndImageContext
void UIGraphicsEndImageContext(void);
从栈顶移除当前的基于位图的图形上下文。
UIRectClip
void UIRectClip(CGRect rect);
修改与当前剪切路径相交的矩形区域。
例子:获取一块区域
- (UIImage *)getImage
{
UIGraphicsBeginImageContext(self.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
UIRectClip(CGRectMake(0.0, 0.0, self.bounds.size.width, self.bounds.size.height / 2.0));
[self.layer renderInContext:context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
UIRectFill
void UIRectFill(CGRect rect);
用当前的颜色来填充指定的区域。
在iOS4以后的系统中,你可以在你的应用程序的任何线程中调用这个方法。
例子:用红色填充一个矩形
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
UIRectFill(CGRectMake(100.0, 100.0, 100.0, 100.0));
UIRectFillUsingBlendMode
void UIRectFillUsingBlendMode(CGRect rect, CGBlendMode blendMode);
在当前图形上下文中绘制矩形区域。如果当前图形上下文为nil,这个方法什么也不做。
在iOS4以后的系统中,你可以在你的应用程序的任何线程中调用这个方法。
UIRectFrame
void UIRectFrame(CGRect rect);
围绕指定矩形内部区域绘制一个框架。
在iOS4以后的系统中,你可以在你的应用程序的任何线程中调用这个方法。
例子:绘制一个矩形边框
UIRectFrame(CGRectMake(100.0, 100.0, 100.0, 100.0));
UIRectFrameUsingBlendMode
void UIRectFrameUsingBlendMode(CGRect rect, CGBlendMode blendMode);
同 UIRectFrame方法,多了一个混合模式。
在iOS4以后的系统中,你可以在你的应用程序的任何线程中调用这个方法。
PDF Creation
UIGraphicsBeginPDFContextToData
void UIGraphicsBeginPDFContextToData(NSMutableData *data, CGRect bounds, NSDictionary *documentInfo) NS_AVAILABLE_IOS(3_2);
创建一个目标为指定可变数据对象的基于PDF的图形上下文。
例子:
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/abc.pdf"];
NSMutableData *data = [[NSMutableData alloc] init];
UIGraphicsBeginPDFContextToData(data, CGRectZero, nil);
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
CGContextRef context = UIGraphicsGetCurrentContext();
[_imageView.layer renderInContext:context];
[@"Hello PDF!" drawAtPoint:CGPointMake(380.0, 100.0) withFont:[UIFont boldSystemFontOfSize:30.0]];
UIGraphicsEndPDFContext();
[data writeToFile:path atomically:YES];
UIGraphicsBeginPDFContextToFile
BOOL UIGraphicsBeginPDFContextToFile(NSString *path, CGRect bounds, NSDictionary *documentInfo) NS_AVAILABLE_IOS(3_2);
存储PDF文件的路径,可以是相对路径也可以是绝对路径。如果在指定的路径下没有这个文件,那么就创建一个文件;相反,已经存在的文件内容就会被清除。目录路径必须存在。
例子:
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/abc.pdf"];
UIGraphicsBeginPDFContextToFile(path, CGRectZero, nil);
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
CGContextRef context = UIGraphicsGetCurrentContext();
[_imageView.layer renderInContext:context];
[@"Hello PDF!" drawAtPoint:CGPointMake(380.0, 100.0) withFont:[UIFont boldSystemFontOfSize:30.0]];
UIGraphicsEndPDFContext();
UIGraphicsEndPDFContext
void UIGraphicsEndPDFContext(void) NS_AVAILABLE_IOS(3_2);
关闭PDF图形上下文并从当前图形上下文栈顶弹出。
在完成一个PDF图形上下文的绘制时必须调用这个方法。这个方法关闭当前打开的页面并且把PDF图形上下文从栈中移除,同样也会释放与PDF上下文相关的 CGContextRef 实例。如果当前的不是PDF上下文,这个方法什么也不做。
void UIGraphicsBeginPDFPage(void)NS_AVAILABLE_IOS(3_2);
UIGraphicsBeginPDFPage
void UIGraphicsBeginPDFPage(void) NS_AVAILABLE_IOS(3_2);
在PDF图形上下文中标记一个新的页面并使用默认值进行配置。
这个方法在开启一个新的页面之前会结束任何上一个页面。当你创建完PDF图形上下文时会给指定矩形区域内的新页面设置一个媒体盒。
如果当前的上下文不是一个PDF图形上下文,那么这个方法什么也不做。
在你发出任何绘制命令之前,你必须要调用这个方法或者 UIGraphicsBeginPDFPageWithInfo 这个方法。
UIGraphicsBeginPDFPageWithInfo
void UIGraphicsBeginPDFPageWithInfo(CGRect bounds, NSDictionary *pageInfo) NS_AVAILABLE_IOS(3_2);
在PDF图形上下文中标记一个新的页面并使用指定的值进行配置。
bounds:
新PDF页面中指定大小和位置的矩形框。这个矩形相当于页面的媒体框矩形。
pageInfo:
一个指定特定额外与页面相关信息的字典,比如定义页面不同部分的矩形框。有一个数组的keys你可以在这个字典众使用,在 CGPDFContext Reference 中查看box 字典keys。这个字典是这个新页面所拥有的,所以在这个方法返回之后你需要释放这个字典。
如果你这个页面不想使用任何额外的信息那么就设定为nil。
这个方法在开启一个新的页面之前会结束任何上一个页面。设置新页面媒体框的值在pageInfo字典的 kCGPDFContextMediaBox key中,或者如果这个字典不包含这个key,那么这个值就在bounds参数中。
如果当前的上下文不是一个PDF图形上下文,那么这个方法什么也不做。
在你发出任何绘制命令之前,你必须要调用这个方法或者 UIGraphicsBeginPDFPageWithInfo 这个方法。
UIGraphicsGetPDFContextBounds
CGRect UIGraphicsGetPDFContextBounds(void) NS_AVAILABLE_IOS(3_2);
返回与PDF上下文关联的当前页面边界或者如果当前上下文不是PDF图形上下文就返回CGRectZero。
如果一个页面还没有开始绘制,这个方法返回当创建PDF图形上下文时指定的默认媒体框,否则,返回当前页面的边界。
UIGraphicsAddPDFContextDestinationAtPoint
void UIGraphicsAddPDFContextDestinationAtPoint(NSString *name, CGPoint point) NS_AVAILABLE_IOS(3_2);
在当前页面创建一个跳转目的地。
例子:点击PDF的(100.0, 0.0, 200.0, 30.0)这个区域将会跳到PDF的(0, pdfFrame.size.height)这个位置。
UIGraphicsAddPDFContextDestinationAtPoint(@"Chapter12", CGPointMake(0, pdfFrame.size.height));
UIGraphicsSetPDFContextDestinationForRect(@"Chapter12", CGRectMake(100.0, 0.0, 200.0, 30.0));
UIGraphicsSetPDFContextDestinationForRect
void UIGraphicsSetPDFContextDestinationForRect(NSString *name, CGRect rect) NS_AVAILABLE_IOS(3_2);
链接当前页面上的一个矩形到指定的跳转目的地。
你使用这个方法在PDF文档众创建一个实时的链接。点击PDF文档中指定的区域会使文档显示与跳转目的地相关的内容。
UIGraphicsSetPDFContextURLForRect
void UIGraphicsSetPDFContextURLForRect(NSURL *url, CGRect rect) NS_AVAILABLE_IOS(3_2);
链接当前页面上的矩形区域到指定的URL地址,点击rect区域将会打开url链接。
当前图形上下文中的一个矩形区域。
例子:
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/abc.pdf"];
UIGraphicsBeginPDFContextToFile( path, CGRectZero, nil );
CGRect pdfFrame = CGRectMake(0, 0, 596, 1842);
UIGraphicsBeginPDFPageWithInfo(pdfFrame, nil);
NSURL *url = [NSURL URLWithString:@"http://blog.youkuaiyun.com/lixuwen521/article/details/16879597"];
CGRect textFrame = CGRectMake(10, 10, 100, 20);
CGRect linkFrame = textFrame;
linkFrame.origin.y = pdfFrame.size.height - linkFrame.origin.y - linkFrame.size.height;
UIGraphicsSetPDFContextURLForRect(url, linkFrame);
[[UIColor blueColor] setFill];
[@"Chapter1" drawAtPoint:CGPointMake(100.0, pdfFrame.size.height - 30) withFont:[UIFont boldSystemFontOfSize:30.0]];
UIGraphicsAddPDFContextDestinationAtPoint(@"Chapter12", CGPointMake(0, pdfFrame.size.height));
UIGraphicsSetPDFContextDestinationForRect(@"Chapter12", CGRectMake(100.0, 0.0, 200.0, 30.0));
NSNumber *underline = [NSNumber numberWithInt:NSUnderlineStyleSingle];
NSDictionary *attributesDict = @{NSUnderlineStyleAttributeName:underline, NSForegroundColorAttributeName:[UIColor blueColor]};
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"博客地址" attributes:attributesDict];
[attString drawInRect:textFrame];
UIGraphicsEndPDFContext();
String Conversions
CGAffineTransformFromString
CGAffineTransform CGAffineTransformFromString(NSString *string);
返回一个通过仿射变换的与给定字符串相对应的数据的结构体。
CGPointFromString
CGPoint CGPointFromString(NSString *string);
把字符串@"{x, y}"转换成CGPoint。
CGRectFromString
CGRect CGRectFromString(NSString *string);
把字符串@"{{x, y}, {width, height}}"转换成CGRect。
CGSizeFromString
把字符串@"{width, height}"转换成CGSize。UIEdgeInsetsFromString
UIEdgeInsets UIEdgeInsetsFromString(NSString *string);
NSStringFromUIOffset
NSString *NSStringFromUIOffset(UIOffset offset);
把UIOffset(horizontal, vertical)转换成字符串。
NSStringFromCGAffineTransform
NSString *NSStringFromCGAffineTransform(CGAffineTransform transform);
把 CGAffineTransform 格式的数据转换成字符串。
NSStringFromCGPoint
NSString *NSStringFromCGPoint(CGPoint point);
把CGPoint转换成字符串@"{x, y}".
NSStringFromCGRect
NSString *NSStringFromCGSize(CGSize size);
把CGSize转换成字符串@"{width, heigh}".
NSStringFromCGRect
NSString *NSStringFromCGRect(CGRect rect);
把CGRect转换成字符串@"{{x, y}, {width, heigh}}".
NSStringFromUIEdgeInsets
NSString *NSStringFromUIEdgeInsets(UIEdgeInsets insets);
把UIEdgeInsets转换成字符串。
NSStringFromUIOffset
NSString *NSStringFromUIOffset(UIOffset offset);
把UIOffset转换成字符串。
Managing Edge Insets
UIEdgeInsets UIEdgeInsetsMake
UIKIT_STATIC_INLINE UIEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) {
UIEdgeInsets insets = {top, left, bottom, right};
return insets;
}
为一个button或者view创建一个边框偏移。
UIEdgeInsetsEqualToEdgeInsets
UIKIT_STATIC_INLINE BOOL UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsets insets1, UIEdgeInsets insets2) {
return insets1.left == insets2.left && insets1.top == insets2.top && insets1.right == insets2.right && insets1.bottom == insets2.bottom;
}
判断两个UIEdgeInsets是否相同。
UIEdgeInsetsInsetRect
UIKIT_STATIC_INLINE CGRect UIEdgeInsetsInsetRect(CGRect rect, UIEdgeInsets insets) {
rect.origin.x += insets.left;
rect.origin.y += insets.top;
rect.size.width -= (insets.left + insets.right);
rect.size.height -= (insets.top + insets.bottom);
return rect;
}
按照给丁的UIEdgeInsets调整CGRect。
Managing Offsets
UIOffsetMake
UIKIT_STATIC_INLINE UIOffset UIOffsetMake(CGFloat horizontal, CGFloat vertical) {
UIOffset offset = {horizontal, vertical};
return offset;
}
创建UIOffset。
UIOffsetEqualToOffset
UIKIT_STATIC_INLINE BOOL UIOffsetEqualToOffset(UIOffset offset1, UIOffset offset2) {
return offset1.horizontal == offset2.horizontal && offset1.vertical == offset2.vertical;
}
判断两个UIOffset是否相等。
Interface Orientation Macros
UIInterfaceOrientationIsPortrait
#define UIInterfaceOrientationIsPortrait(orientation) ((orientation) == UIInterfaceOrientationPortrait || (orientation) == UIInterfaceOrientationPortraitUpsideDown)
判断当前界面方向是不是竖屏的。
UIInterfaceOrientationIsLandscape
#define UIInterfaceOrientationIsLandscape(orientation) ((orientation) == UIInterfaceOrientationLandscapeLeft || (orientation) == UIInterfaceOrientationLandscapeRight)
判断界面方向是不是横屏的。用法同 UIInterfaceOrientationIsPortrait 。
Device Orientation Macros
UIDeviceOrientationIsValidInterfaceOrientation
#define UIDeviceOrientationIsValidInterfaceOrientation(orientation) ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown || (orientation) == UIDeviceOrientationLandscapeLeft || (orientation) == UIDeviceOrientationLandscapeRight)
判断设备的转向是否是有效的。
例子:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
//先判断是否有效转向
if( UIDeviceOrientationIsValidInterfaceOrientation( toInterfaceOrientation ) )
{
// Do what you want to do....
}
}
UIDeviceOrientationIsPortrait
#define UIDeviceOrientationIsPortrait(orientation) ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown)
判断设备是不是竖屏的。
UIDeviceOrientationIsLandscape
#define UIDeviceOrientationIsLandscape(orientation) ((orientation) == UIDeviceOrientationLandscapeLeft || (orientation) == UIDeviceOrientationLandscapeRight)
判断设备是不是横屏的。
Interface Idiom Macro
UI_USER_INTERFACE_IDIOM
#define UI_USER_INTERFACE_IDIOM() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone)
判断当前设备是否支持 interface idiom。
如果当前设备为iPhone 或者iPod touch,那么userInterfaceIdiom就为UIUserInterfaceIdiomPhone,如果为iPad就为UIUserInterfaceIdiomPad.
Accessibility
UIAccessibilityPostNotification
void UIAccessibilityPostNotification(UIAccessibilityNotifications notification, id argument);
传递一个消息给辅助的应用。
UIAccessibilityIsVoiceOverRunning
BOOL UIAccessibilityIsVoiceOverRunning() NS_AVAILABLE_IOS(4_0);
判断VoiceOver是否打开(运行)。
Declared In UIAccessibility.h
UIAccessibilityIsClosedCaptioningEnabled
BOOL UIAccessibilityIsClosedCaptioningEnabled() NS_AVAILABLE_IOS(5_0);
判断隐藏式字幕是否可用。
Declared In UIAccessibility.h
UIAccessibilityRequestGuidedAccessSession
void UIAccessibilityRequestGuidedAccessSession(BOOL enable, void(^completionHandler)(BOOL didSucceed)) NS_AVAILABLE_IOS(7_0);
completionHandler:
这个block会通知你的App操作成功还是失败。
Declared In UIAccessibility.hUIAccessibilityIsGuidedAccessEnabled
BOOL UIAccessibilityIsGuidedAccessEnabled() NS_AVAILABLE_IOS(6_0);
判断引导式访问功能是否可用。
Declared In UIAccessibility.h
UIAccessibilityIsInvertColorsEnabled
BOOL UIAccessibilityIsInvertColorsEnabled() NS_AVAILABLE_IOS(6_0);
UIAccessibilityIsMonoAudioEnabled
BOOL UIAccessibilityIsMonoAudioEnabled() NS_AVAILABLE_IOS(5_0);
UIAccessibilityZoomFocusChanged
void UIAccessibilityZoomFocusChanged(UIAccessibilityZoomType type, CGRect frame, UIView *view) NS_AVAILABLE_IOS(5_0);
Declared In UIAccessibilityZoom.h
UIAccessibilityRegisterGestureConflictWithZoom
void UIAccessibilityRegisterGestureConflictWithZoom() NS_AVAILABLE_IOS(5_0);
UIAccessibilityConvertFrameToScreenCoordinates
UIAccessibilityConvertFrameToScreenCoordinates(CGRect rect, UIView *view) NS_AVAILABLE_IOS(7_0);
把指定矩形的视图坐标转换成屏幕坐标系统。
rect:
在指定view坐标系中的特定矩形区域。
view:
包含特定矩形的view。这个参数不能为nil。
Declared In UIAccessibility.h
UIAccessibilityConvertPathToScreenCoordinates
UIBezierPath *UIAccessibilityConvertPathToScreenCoordinates(UIBezierPath *path, UIView *view) NS_AVAILABLE_IOS(7_0);
把指定的路径对象转换成屏幕坐标系统的并且返回一个有结果的新路径对象。路径样式一样,但是路径上的点是屏幕坐标系的。
Text Manipulations
NSTextAlignmentFromCTTextAlignment
CTTextAlignment NSTextAlignmentToCTTextAlignment(NSTextAlignment nsTextAlignment);
nsTextAlignment:
你想转换测UIKit 文本对齐常量。
当你需要在UIKit和Core Text对齐常量之间进行映射的时候就调用这个方法。
Declared In NSText.h。
NSTextAlignmentToCTTextAlignment
CTTextAlignment NSTextAlignmentToCTTextAlignment(NSTextAlignment nsTextAlignment);
Declared In NSText.h。
Guided Access Restriction State
UIGuidedAccessRestrictionStateForIdentifier
UIGuidedAccessRestrictionState UIGuidedAccessRestrictionStateForIdentifier(NSString *restrictionIdentifier) NS_AVAILABLE_IOS(7_0);
返回指定引导访问限制的限制状态。
restrictionIdentifier:
引导访问限制的唯一地标识字符串。
所有限制的初始化状态为 UIGuidedAccessRestrictionStateAllow.
Declared In UIGuidedAccessRestrictions.h