【发布时间】:2016-02-04 21:43:53
【问题描述】:
我是 xcode 的初学者,我想为我的目标 C 应用程序使用 Air Print 进行打印。这是我目前拥有的代码。
-(IBAction)Print {
UIImage *image = [UIImage imageNamed:@"picTwizzlerfw.png"];
NSMutableString *printBody = [NSMutableString stringWithFormat:@"%@",_TextField.text];
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
//pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"PrintJob";
pic.printInfo = printInfo;
UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc] initWithText:printBody];
textFormatter.startPage = 0;
textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0);
textFormatter.maximumContentWidth = 6 * 72.0;
pic.printFormatter = textFormatter;
pic.showsPageRange = YES;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"Printing could not complete because of error: %@", error);
}
};
[pic presentAnimated:YES completionHandler:completionHandler];
}
现在它正在打印TextField,但我希望它打印image。如果有人可以提供帮助,那就太好了!
【问题讨论】:
-
为什么不在图片中使用
UIActivityViewController?然后用户可以选择他们想要对图像执行的任何操作,包括打印。
标签: ios objective-c uiprintinteractioncntrler