我仍然是OSX / Swift 3.1的新手,但我有点难过,我建立了一个epos系统,它的工作都很好,我只是坚持打印收据。
我已经构建了一个XIB视图,并在其下面显示了相应的swift文件
class Receipt: NSView {
let currentOrder = NewOrder.instance
@IBOutlet var view: NSView!
@IBOutlet weak var facebookString: NSTextField!
@IBOutlet weak var websiteString: NSTextField!
@IBOutlet weak var totalString: NSTextField!
@IBOutlet weak var vatString: NSTextField!
@IBOutlet weak var subTotalString: NSTextField!
@IBOutlet weak var CashierName: NSTextField!
@IBOutlet weak var orderNumber: NSTextField!
@IBOutlet weak var date: NSTextField!
@IBOutlet weak var itemList: NSTextField!
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
Bundle.main.loadNibNamed("ReceiptView", owner: self, topLevelObjects: nil)
let contentFrame = NSMakeRect(0, 0, frame.size.width, frame.size.height)
self.view.frame = contentFrame
self.addSubview(self.view)
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
subTotalString.stringValue = "Hello World"
view.draw(dirtyRect)
subTotalString.draw(dirtyRect)
}
}
我已将nib名称添加到XIB引用并加载了一个新的Receipt()类,并将该视图添加到NSPrintOperation。
let order = NewOrder.instance
let sview = Receipt()
let printer = NSPrinter(name: "EPSON TM-T88V");
let printData = NSPrintInfo()
printData.printer = printer!
let printerName = printer?.name
let docSize = NSMakeSize(CGFloat(204.0), CGFloat(200));
let res = "180x180dpi";
let speed = "Auto";
let blank = "Off";
let paperCut = "DocFeedCut";
let chashDrwr1 = "After";
let chashDrwr2 = "Off";
let buzzerControl = "Off";
let buzzerPattern = "Internal";
let buzzerRepeat = "1";
let data = TMPrintSupport.tmSetJobTicket(printData, printerName: printerName, documentSize: docSize, resolution: res, speed: speed, blank: blank, paperCut: paperCut, chashDrwr1: chashDrwr1, chashDrwr2: chashDrwr2, buzzerControl: buzzerControl, buzzerPattern: buzzerPattern, buzzerRepeat: buzzerRepeat)
let po = NSPrintOperation(view: sview.view, printInfo: printData)
// po.showsPrintPanel = false
po.canSpawnSeparateThread = true
po.cleanUp()
return po.run()
当显示打印视图时,它是空白的,不包含视图并且是空白的,我也测试打印并且打印只是空白。
欢迎任何建议,谢谢