羊羊羊羊 2013-05-09 05:49 采纳率: 0%
浏览 3012
已采纳

IOS中使用printer打印数组

在IOS中有三个nsmutable数组。要使用printer打印类似下面的数据,怎么实现?

举例:

 0.5    1    10
 1      10   11
 2      5    22
 3      4    6
  • 写回答

1条回答 默认 最新

  • loveiflower 2013-05-09 07:19
    关注

    UIPrintInteractionController来实现:

    具体代码:

    NSMutableString *stringToPrint = [[NSMutableString alloc] initWithString:@""];
    for(int i = 0;i<[array count];i++)
    {
        [stringToPrint appendFormat:@"%@",[array objectAtIndex:i]];
        if(i%2 == 0)
        {
            [stringToPrint appendFormat:@"\n"];
        }
        else
        {
             [stringToPrint appendFormat:@"\t"];
        }
    }
    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    
    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName = @"Midhun";
    pic.printInfo = printInfo;
    
    UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc]
                                                 initWithText:stringToPrint];
    textFormatter.startPage = 0;
    textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // 1 inch margins
    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);
        }
    };
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        [pic presentFromBarButtonItem:sender animated:YES completionHandler:completionHandler];
    }
    else
    {
        [pic presentAnimated:YES completionHandler:completionHandler];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!