我正在尝试通过 iPad 应用程序设置打印,单击打印将打印包含所有内容的视图。这是我尝试过的(从网上的几个例子中总结出来的):
// This is the View I want to print
// Just a 200x200 blue square
var testView = UIView(frame: CGRectMake(0, 0, 200, 200))
testView.backgroundColor = UIColor.blueColor()
let printInfo = UIPrintInfo(dictionary:nil)!
printInfo.outputType = UIPrintInfoOutputType.General
printInfo.jobName = "My Print Job"
// Set up print controller
let printController = UIPrintInteractionController.sharedPrintController()
printController!.printInfo = printInfo
// This is where I was thinking the print job got the
// contents to print to the page??
printController?.printFormatter = testView.viewPrintFormatter()
// Do it
printController!.presentFromRect(self.frame, inView: self, animated: true, completionHandler: nil)
但是,我也在这里读到了viewPrintFormatter
仅适用于 UIWebView、UITextView 和 MKMapView 的内容,对吗?
当我用这个(使用打印机模拟器)打印时,我只得到一个空白页;尝试使用各种打印机/纸张尺寸。
非常感谢任何指导!