With AirPrint, you can easily transfer lossless photo and document printing from IOS and OS X apps. Of course, printers also need to support AirPrint technology. The following sample shows how to print using AirPrint in an app.
1, Printer simulator (Printer Simulator) Download
It doesn't matter if you don't have a printer that supports AirPrint, Apple offers a virtual printer, address: https://developer.apple.com/downloads
(1) Download the hardware IO Tools inside
(2) Printer Simulator in the running kit
(3) Open a Web page with a browser, use the simulator to print a look at the effect
If the mobile phone and computer under the same network segment, the use of mobile phones can also be found on the computer printer simulator.
The following is the print effect, you can see that the virtual printer generated a PDF file, this and the actual printing results are consistent.
2, print a piece of text using AirPrint
(1) When printing will pop up the page (left) so that you choose the printer, print copies of the number and so on. The preview effect is shown below
(2) The right picture is the final printed file
The code is as follows |
Copy Code |
Import Uikit
Class Viewcontroller:uiviewcontroller {
Override Func Viewdidload () { Super.viewdidload () }
@IBAction func Printtext (sender:anyobject) { Print Controller Let Printcontroller = Uiprintinteractioncontroller.sharedprintcontroller () Print task-related information Let Printinfo = Uiprintinfo (Dictionary:nil) Printinfo.outputtype = Uiprintinfooutputtype.general Printinfo.jobname = "My Print Job" Printcontroller.printinfo = Printinfo
Set up printed text Let Printtext = "<div style= ' Font-size:28px;font-weight:bold;text-align:center ' >" + "Hangge.com</div>" + "Do the best developer Knowledge Platform"
Format printed text Let formatter = Uimarkuptextprintformatter (Markuptext:printtext) Set page insets margins Formatter.contentinsets = Uiedgeinsets (top:72, left:72, bottom:72, right:72) Printcontroller.printformatter = Formatter Provides a print interface for users to select the number of printers and replicas Printcontroller.presentanimated (True, Completionhandler:nil) }
Override Func didreceivememorywarning () { Super.didreceivememorywarning () } } |
All right, the above is the 111CN small series for you to arrange for the swift use of AirPrint for printing examples, I hope this article can bring help to you oh.