2016-02-04 61 views
0

我是xcode的初學者,我想使用Air Print打印我的目標C應用程序。這是我目前的代碼。空氣打印圖像目標c

-(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。如果有人能幫上忙,那就太棒了!

+0

爲什麼不使用'UIActivityViewController'與圖像?然後,用戶可以選擇他們想要對圖像執行的任何操作,包括打印。 – rmaddy

回答

0

地址:

pic.printingItem = image; 

和刪除文本格式:

pic.printFormatter = textFormatter;