iosswiftipaduiprintinteractioncntrler

Color print preview not showing UILabels


In iPad print preview not showing UILabels. When I zoom in the print preview it showing properly. When I changed UILabel opaque property to true it will change the UILabel's background to black and display on print preview. This is the code I used to show print preview.

let printController = UIPrintInteractionController.shared
let printInfo = UIPrintInfo(dictionary:nil)
printInfo.outputType = UIPrintInfoOutputType.general
printInfo.jobName = "Print"
printInfo.duplex = UIPrintInfoDuplex.none
printInfo.orientation = UIPrintInfoOrientation.portrait

printController.printPageRenderer = nil
printController.printingItems = nil
printController.printingItem = printUrl

printController.printInfo = printInfo
printController.showsNumberOfCopies = true
printController.showsPaperSelectionForLoadedPapers = true

printController.present(animated: true, completionHandler: nil)

When I change UIPrintInfoOutputType.general to UIPrintInfoOutputType.grayscale it will display the UILabels, but I need color print. Grayscale is only for black & white printing.


Solution

  • I tried many ways to solve my problem, and finally I found a solution.

    I changed the opaque property of UILabel to true and then changed the background color of UILabel to white. The problem was, the background color of UILabel was Default. So that, In print preview the background of UILabel was shown in black. If the background color of UILabel is Default or Clear Color it will show in black in print preview.

    printLabel.isOpaque = true
    printLabel.backgroundColor = UIColor.white //Not Default or Clear Color