相关疑难解决方法(0)

如何在iOS 4.2中打印?

我想在我的应用程序中集成打印功能.

我要打印的文档将采用.doc或.txt格式.我在iPhone开发方面还不是很有经验,因此很难通过Apple文档来实现它.

如果有人可以通过发布一些示例代码来帮助我,那将是一个很大的帮助.

printing iphone cocoa-touch ipad ios-4.2

24
推荐指数
1
解决办法
1万
查看次数

使用Swift生成PDF

我想从Swift中的UITableView创建一个PDF.我发现了Objective C的一些教程,并尝试了但是这段代码仍然没有生成文件.

        // get a temprorary filename for this PDF

        var path = NSTemporaryDirectory();
        var pdfFilePath = path.stringByAppendingPathComponent("mypdfdocument.pdf")

        UIGraphicsBeginPDFContextToFile(pdfFilePath, CGRectMake(0, 0, self.tableView.contentSize.width, self.tableView.contentSize.height), nil)
        UIGraphicsBeginPDFPage();
        self.view.layer.renderInContext(UIGraphicsGetCurrentContext())
        self.tableView.scrollRectToVisible(CGRectMake(0, 0, 1, 1), animated: false)
        self.tableView.layer.renderInContext(UIGraphicsGetCurrentContext())

        var screensInTable = Int(self.tableView.contentSize.width) / Int(self.tableView.contentSize.height)

        for i in 1...screensInTable {

            var point = CGFloat(CGFloat(i) * self.tableView.bounds.height)
            var contentOffset:CGPoint = CGPointMake(0, point)
            self.tableView.setContentOffset(contentOffset, animated: false)
            self.tableView.layer.renderInContext(UIGraphicsGetCurrentContext())
        }

        UIGraphicsEndPDFContext();
Run Code Online (Sandbox Code Playgroud)

而且:我有一个包含4个部分的表和不同的行高和单元格模板.是否有机会使用此类代码轻松生成PDF?或者使用CoreText创建Row by Row会更好吗?

提前致谢.

ios swift

7
推荐指数
1
解决办法
2万
查看次数

一个UIView的AirPrint内容

我正在尝试通过iPad应用程序设置打印,单击"打印"将打印包含其所有内容的视图.以下是我尝试过的内容(通过网上的几个例子汇总):

// This is the View I want to print
// Just a 200x200 blue square
var testView = UIView(frame: CGRectMake(0, 0, 200, 200))
testView.backgroundColor = UIColor.blueColor()

let printInfo = UIPrintInfo(dictionary:nil)!
printInfo.outputType = UIPrintInfoOutputType.General
printInfo.jobName = "My Print Job"

// Set up print controller
let printController = UIPrintInteractionController.sharedPrintController()
printController!.printInfo = printInfo
// This is where I was thinking the print job got the
// contents to print to the page??
printController?.printFormatter = testView.viewPrintFormatter()

// Do it
printController!.presentFromRect(self.frame, inView: self, animated: …
Run Code Online (Sandbox Code Playgroud)

uiview airprint uiprintformatter swift

5
推荐指数
1
解决办法
3403
查看次数