美文网首页iOS Developer
tableView 屏幕截图并使用AirPrint打印

tableView 屏幕截图并使用AirPrint打印

作者: 简简单单写书 | 来源:发表于2017-07-21 16:07 被阅读113次

项目中要求tableView的截图,转为Data,并用AirPrint 打印出来,特地总结一下

tableView截图

<pre>
func imageFromTableView(tableView: UITableView) -> UIImage {

    var image = UIImage()
    //开上下文
    UIGraphicsBeginImageContextWithOptions(tableView.contentSize, tableView.isOpaque, 0.0)
    //保存frame
    let savedContentOffset = tableView.contentOffset
    let savedFarme = tableView.frame
    //设置tableView在画布的位置和大小
    tableView.contentOffset = .zero
    tableView.frame = CGRect(x: 0, y: 0, width: tableView.contentSize.width, height: tableView.contentSize.height)
    // 开始画
    tableView.layer.render(in: UIGraphicsGetCurrentContext()!)
    //生成图片保存在image中
    image = UIGraphicsGetImageFromCurrentImageContext()!
    //还原tableView的frame
    tableView.contentOffset = savedContentOffset
    tableView.frame = savedFarme
    //关闭上下文
    UIGraphicsEndImageContext()
    
    return image
}

</pre>

image使用AirPrint打印

<pre>
let pic = UIPrintInteractionController.shared // 创建控制器
let printInfo = UIPrintInfo.printInfo() // 打印机配置

// UIPrintInfoOutputType:给 UIKit 提供要打印内容的类型提示。可以是以下任意一个:
// .General(默认):文本和图形混合类型;允许双面打印。
// .Grayscale:如果你的内容只包括黑色文本,那么该类型比 .General 更好。
// .Photo:彩色或黑白图像;禁用双面打印,更适用于图像媒体的纸张类型。
// .PhotoGrayscale:对于仅灰度的图像,根据打印机的不同,该类型可能比 .Photo 更好。
printInfo.outputType = .general
pic.printInfo = printInfo
pic.showsNumberOfCopies = false //让用户选择打印范围,只在多页的时候有用
pic.printingItem = image // 输入源
//ipad 的调用方式
pic.present(from: rect, in: inView, animated: true, completionHandler: { (pick, isSuccess, error) in

        })

// iphone 的调用方式
// pic.present(animated: true, completionHandler: { (pick, isSuccess, error) in })
</pre>

此时就会弹出打印页面,但是系统自带的显示的是英文此时需要修改info.plist中的文件,将en改为China

修改语言

相关文章

  • tableView 屏幕截图并使用AirPrint打印

    项目中要求tableView的截图,转为Data,并用AirPrint 打印出来,特地总结一下 tableView...

  • iOS打印 AirPrint

    使用iOS AirPrint 让你的APP轻松实现打印功能 1, 什么是AirPrint 其实就是将iOS(iph...

  • iOS打印 AirPrint

    使用iOS AirPrint 让你的APP轻松实现打印功能 2016/05/13 · iOS开发 · 打印分享到:...

  • Ubuntu截图工具

    ubuntu|flameshot|截图工具 使用Flameshot获取屏幕截图并编辑 功能概述 注释(高亮、标示、...

  • iOS打印 AirPrint 及 普通打印机如何适配

    1.什么是AirPrint AirPrint是可以让应⽤用软件通过Apple的⽆无驱动程序打印体系结构,创建⽆无损...

  • iOS 截图

    1、屏幕截图 2、scrollView、tableView的截图 类似于上面的截图,会有一定的问题,如果你用sel...

  • AriPrint

    参考文档1参考文档2目前多数打印机已经可以支持苹果的AirPrint功能,刚完成的项目使用的打印机自身有相应的SD...

  • iOS 打印 AirPrint无线打印

    主要功能:使用iPhone、PC连接同一个WiFi,iPhone 上App有打印功能,点击打印,实现打印文档功能。...

  • iOS开发--Airprint

    Airprint是iOS系统自带的打印服务框架,利用她可以很简单系统打印服务,打印word,PDF,图片,也可以打...

  • iOS 使用AirPrint实现无线打印功能

    无线打印打印流程 a.创建 UIPrintInteractionController 实例。 b.创建UIPrin...

网友评论

    本文标题:tableView 屏幕截图并使用AirPrint打印

    本文链接:https://www.haomeiwen.com/subject/nsfjkxtx.html