【问题标题】:Air Print images objective c空气打印图像物镜 c
【发布时间】: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


【解决方案1】:

添加:

pic.printingItem = image;

并删除文本格式化程序:

pic.printFormatter = textFormatter;

【讨论】:

    猜你喜欢
    • 2011-10-25
    • 1970-01-01
    • 2016-11-26
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多