I am wanting to know how to Air print just a UILabel in swift

时间:2017-10-12 09:40:49

标签: ios

here is my code, I am unsure on how to AirPrint the UILabel. If anyone could help me out that would be highly appreciated.

@IBOutlet weak var cityLbl: UILabel!

@IBAction func printButton(_ sender: Any) {

    self.printText()

}

func printText() {
    let printController = UIPrintInteractionController.shared

    let printI = UIPrintInfo(dictionary: nil)

    printI.jobName = "printing this image"
    printI.outputType = .general

    printController.printInfo = printI


    printController.printingItem = cityLbl


    printController.present(animated: true) { (_, isPrinted, error) in

        if error == nil {
            if isPrinted {
                print("image is printed")
            } else {
                print("image is not printed")
            }
        }
    }

}

1 个答案:

答案 0 :(得分:0)

you check is this item is printable or not

func printText() {
    if UIPrintInteractionController.canPrint(cityLbl) {
        //your code
    }
}