sri*_*sri 7 iphone objective-c airprint
From my application, how can I allow a user to print a document or page from an iPhone or iPad? Which versions of iOS support printing?
Big*_*ump 18
这是一个简单的代码.
-(void)printItem {
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *imageFromCurrentView = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];
printController.printingItem = imageFromCurrentView;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGrayscale;
printController.printInfo = printInfo;
printController.showsPageRange = YES;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
}
};
[printController presentAnimated:YES completionHandler:completionHandler];
}
Run Code Online (Sandbox Code Playgroud)
您可以在任何运行iOS 4.2或更高版本的多任务处理设备上打印.有关详细信息,请参阅此处:http://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/Printing/Printing.html#//apple_ref/doc/uid/TP40010156-CH12-SW1
| 归档时间: |
|
| 查看次数: |
5035 次 |
| 最近记录: |