首先,我道歉,对于缺乏图像。 显然,我仍然过新来做到这一点。 我将尝试描述问题的口头和提供的两个关键部分的代码。
我打印一个电视时间表,排的时隙。 当我显示的看到我的mac os屏幕上看,它看起来像这样的东西:
40. 8:00 AM 8:30 AM
CNN. Bla Bla Bla Talk Show 1. Whatever Talk Show 1, with
Guests to discuss price Great Host
of bla bla bla. Host will talk about
Whatever
但当我打印出来,它截断一些,但不一定是所有的两行文字的物品,如下所示:
40. 8:00 AM 8:30 AM
CNN. Bla Bla Bla Talk Sh ... Whatever Talk Show 1, w...
Guests to discuss pr... Host will talk about
Whatever
如果你有注意到的不一致,这是因为它并不完全一致的。 有时候我做得到的双线路输出,但更多的是我得到的截断与省略号。 我还没想出对潜在的模式为何。 但是,只有在打印框架是这一问题。 屏幕上显示的是正是我想要的。
所以我必须猎杀周围的解决方案,并尝试过许多的变化的文本()剂fixedSize()和lineLimit(). fixedSize排序的工作,在这两个行项目不截断,但同样,在印景,行与高的小剪辑发行上面和下面。 这真的很喜欢演戏的NSRect框架的印象是不够大,但这是巨大的,这不应该发生的事情。
该项目太大,无法提供的所有代码,但希望它将能够提供视问题,再加上打印机的逻辑。
视(这显示正确-没有截):
struct ScheduleDisplayView: View {
var schedule: [SchedSlot]
let chanmax: CGFloat = 28.0
let fontsize: CGFloat = 7.0
let cellmax: CGFloat = 120
var sortedData : [DayBlock] {
let schedTree: ScheduleTree = ScheduleTree.init()
for ss in schedule {
schedTree.add(schedSlot: ss)
}
return schedTree.dayList
}
var body: some View {
List {
ForEach(sortedData, id: \.dateStamp) { day in
Text("\(day.dateStamp)")
.bold()
ForEach(day.qList, id: \.QTag) { qblock in
ForEach(qblock.chanList.sorted(by: <), id: \.chanTag) { channel in
HStack(alignment: .top, spacing: 0) {
VStack(spacing: 0) {
Text(String(channel.chanTag))
Text(channel.callSign.prefix(4))
}
.border(Color.yellow)
.frame(maxWidth: chanmax, alignment: .topLeading)
.padding(0)
ForEach(channel.timeList, id: \.timeTag) { timecell in
VStack(spacing: 0) {
Text("\(timecell.timeTag)")
.frame(maxWidth: .infinity, alignment: .topLeading)
ForEach(timecell.cellList, id: \.id) { cell in
if cell.startTime != timecell.timeTag {
Text("\(cell.title) (\(cell.startTime))")
.foregroundColor(.blue)
.frame(maxWidth: .infinity, alignment: .topLeading)
.lineLimit(2)
} else {
Text(cell.title)
.foregroundColor(.blue)
.frame(maxWidth: .infinity, alignment: .topLeading)
.lineLimit(2)
}
Text(cell.subtitle)
.frame(maxWidth: .infinity, alignment: .topLeading)
.lineLimit(2)
}
}
}
.border(Color.green)
.frame(maxWidth: .infinity, alignment: .leading)
}
.font(.system(size: fontsize))
.border(Color.blue)
}
}
}
}
}
}
这里是印刷功能。 它仍然是缺乏分页的功能,但是这是我有什么迄今为止:
func printScheduleView(schedule: [SchedSlot] ) {
let printInfo = NSPrintInfo.shared
printInfo.topMargin = 0.0
printInfo.bottomMargin = 0.0
printInfo.rightMargin = 0.0
printInfo.leftMargin = 0.0
printInfo.horizontalPagination = .fit
printInfo.verticalPagination = .automatic
printInfo.isHorizontallyCentered = false
printInfo.isVerticallyCentered = false
let view = ScheduleDisplayView(schedule: schedule)
let contentRect = NSRect(x: 0, y: 0, width: 900, height: 2800)
let viewToPrint = NSHostingView(rootView: view)
viewToPrint.frame = contentRect
let bitMap = viewToPrint.bitmapImageRepForCachingDisplay(in: contentRect)!
viewToPrint.cacheDisplay(in: contentRect, to: bitMap)
let image = NSImage(size: bitMap.size)
image.addRepresentation(bitMap)
let imageView = NSImageView(frame: contentRect)
imageView.image = image
let printOperation = NSPrintOperation(view: imageView, printInfo: printInfo)
printOperation.showsPrintPanel = true
printOperation.showsProgressPanel = true
printOperation.run()
}