The iOS development swift uses AirPrint to print

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.