Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“打印”按钮如何打印8.5英寸x 11英寸的图像?Swift 3,IOS_Ios_Printing_Swift3_Uiprintinteractioncntrler - Fatal编程技术网

“打印”按钮如何打印8.5英寸x 11英寸的图像?Swift 3,IOS

“打印”按钮如何打印8.5英寸x 11英寸的图像?Swift 3,IOS,ios,printing,swift3,uiprintinteractioncntrler,Ios,Printing,Swift3,Uiprintinteractioncntrler,我试图直接从我的应用程序打印-这是一个清单。唯一的问题是当我打印时,图像将只填充打印纸的1/4。我想让图像填满8.5英寸乘11英寸的整张纸 这是我的打印按钮: @IBAction func buttonAction2(_ sender: UIButton) { //Screenshot of view controller (minus status/Nav bar) let top: CGFloat = 46 let bottom: CGFloat = 0

我试图直接从我的应用程序打印-这是一个清单。唯一的问题是当我打印时,图像将只填充打印纸的1/4。我想让图像填满8.5英寸乘11英寸的整张纸

这是我的打印按钮:

    @IBAction func buttonAction2(_ sender: UIButton) {


    //Screenshot of view controller (minus status/Nav bar)
    let top: CGFloat = 46
    let bottom: CGFloat = 0
    let size = CGSize(width: view.frame.size.width, height: view.frame.size.height - top - bottom)
    UIGraphicsBeginImageContextWithOptions(size, false, 0)
    let context = UIGraphicsGetCurrentContext()!
    context.translateBy(x: 0, y: -top)
    view.layer.render(in: context)
    let snapshot = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    ///Print screenshot
    let printController = UIPrintInteractionController.shared
    let printInfo = UIPrintInfo(dictionary:nil)

    printInfo.jobName = "printing an image"
    printInfo.outputType = .photo

    printController.printInfo = printInfo
    printController.printingItem = snapshot
    printController.present(animated: true)  { (_, isPrinted, error) in if error == nil {
        if isPrinted {
            print("image is printed")
        }else{
            print("image is not printed")
        }
        }
    }

}
我可以将图像保存到我的相机胶卷中,然后从那里打印,而不是直接从我的应用程序打印,这样效果很好。当从“我的相机”卷打印时,图像将填充整个页面:

 //Save photo to camera roll
    UIImageWriteToSavedPhotosAlbum(snapshot!, nil, nil, nil)

不过,我真的需要从应用程序打印。有什么方法可以做到这一点吗?

翻译后您是否尝试过缩放上下文

context.translateBy(x: 0, y: -top)
context.scaleBy(x: 2, y: 2)

我想出来了。我很傻

使用:

而不是:

printInfo.outputType = .photo
图像现在被切掉了75%(从它被放大),仍然只占页面的75%。
printInfo.outputType = .photo