我正在开发一个创建发票的应用程序,并且我试图让我的行部分在高度和宽度的情况下变得灵活,这样我就可以让用户在发票中输入更多行。我的代码和图片以获得更好的想象力如下。
谢谢你们,我坚持了好几天,可能很明显问题:我
我正在使用 X 代码 12.5.1
我的 PDF 课
class PdfCreator : NSObject {
@ObservedObject var userSettings = UserSettings()
private var pageRect : CGRect
private var renderer : UIGraphicsPDFRenderer?
/**
W: 8.5 inches * 72 DPI = 612 points
H: 11 inches * 72 DPI = 792 points
A4 = [W x H] 595 x 842 points
*/
init(pageRect : CGRect =
CGRect(x: 0, y: 0, width: (8.5 * 72.0), height: (11 * 72.0))) {
let format = UIGraphicsPDFRendererFormat()
let metaData = [kCGPDFContextTitle: "Rechnung ()",
kCGPDFContextAuthor: "Vamonos"]
format.documentInfo = metaData as [String: Any]
self.pageRect = pageRect
self.renderer = UIGraphicsPDFRenderer(bounds: self.pageRect,
format: format)
super.init()
}
}
这些也是我在下图中标记的行。我希望这个人有自己的高度灵活的部分,以便用户可以在下面添加另一行。
extension PdfCreator {
private func row( quantity : String) {
let attributes: [NSAttributedString.Key : Any] = [
.font: UIFont.boldSystemFont(ofSize: 12)
]
let rows = CGRect(x: 40 , y: 370,
width: pageRect.width, height: 40)
quantity.draw(in: rows, withAttributes: attributes)
}
private func row2( quantity : String) {
let attributes: [NSAttributedString.Key : Any] = [
.font: UIFont.boldSystemFont(ofSize: 12)
]
let rows = CGRect(x: 100 , y: 370,
width: pageRect.width, height: 40)
quantity.draw(in: rows, withAttributes: attributes)
}
private func row3( quantity : String) {
let attributes: [NSAttributedString.Key : Any] = [
.font: UIFont.boldSystemFont(ofSize: 12)
]
let rows = CGRect(x: 300 , y: 370,
width: pageRect.width, height: 40)
quantity.draw(in: rows, withAttributes: attributes)
}
private func row4( quantity : String) {
let attributes: [NSAttributedString.Key : Any] = [
.font: UIFont.boldSystemFont(ofSize: 12)
]
let rows = CGRect(x: 360 , y: 370,
width: pageRect.width, height: 40)
quantity.draw(in: rows, withAttributes: attributes)
}
private func row5( quantity : String) {
let attributes: [NSAttributedString.Key : Any] = [
.font: UIFont.boldSystemFont(ofSize: 12)
]
let rows = CGRect(x: 420 , y: 370,
width: pageRect.width, height: 40)
quantity.draw(in: rows, withAttributes: attributes)
}
private func row6( quantity : String) {
let attributes: [NSAttributedString.Key : Any] = [
.font: UIFont.boldSystemFont(ofSize: 12)
]
let rows = CGRect(x: 480 , y: 370,
width: pageRect.width, height: 40)
quantity.draw(in: rows, withAttributes: attributes)
}
private func rowFilled( quantity : String) {
let attributes: [NSAttributedString.Key : Any] = [
.font: UIFont.boldSystemFont(ofSize: 12)
]
let rows = CGRect(x: 40 , y: 385,
width: pageRect.width, height: 40)
quantity.draw(in: rows, withAttributes: attributes)
}
private func rowFilled2( quantity : String) {
let attributes: [NSAttributedString.Key : Any] = [
.font: UIFont.boldSystemFont(ofSize: 12)
]
let rows = CGRect(x: 100 , y: 385,
width: pageRect.width, height: 40)
quantity.draw(in: rows, withAttributes: attributes)
}
private func rowFilled3( quantity : String) {
let attributes: [NSAttributedString.Key : Any] = [
.font: UIFont.boldSystemFont(ofSize: 12)
]
let rows = CGRect(x: 300 , y: 385,
width: pageRect.width, height: 40)
quantity.draw(in: rows, withAttributes: attributes)
}
private func rowFilled4( quantity : String) {
let attributes: [NSAttributedString.Key : Any] = [
.font: UIFont.boldSystemFont(ofSize: 12)
]
let rows = CGRect(x: 360 , y: 385,
width: pageRect.width, height: 40)
quantity.draw(in: rows, withAttributes: attributes)
}
private func rowFilled5( quantity : String) {
let attributes: [NSAttributedString.Key : Any] = [
.font: UIFont.boldSystemFont(ofSize: 12)
]
let rows = CGRect(x: 420 , y: 385,
width: pageRect.width, height: 40)
quantity.draw(in: rows, withAttributes: attributes)
}
private func rowFilled6( quantity : String) {
let attributes: [NSAttributedString.Key : Any] = [
.font: UIFont.boldSystemFont(ofSize: 12)
]
let rows = CGRect(x: 480 , y: 385,
width: pageRect.width, height: 40)
quantity.draw(in: rows, withAttributes: attributes)
}
}