I'm trying to have a heading where the whole top of the PDF document is filled with a color.
The standard behaviour seem to be no matter how big I set the CGRect to clip to the edges of the text.
let attributes = [
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 16),
NSAttributedString.Key.backgroundColor : UIColor.red,
NSAttributedString.Key.foregroundColor : UIColor.white
]
let text = "Hello World!"
text.draw(in: CGRect(x: 0, y: 10, width: 2000, height: 2000), withAttributes: attributes)
See image attached.
I have done a dodgy solution but not happy with it as the user can copy the 'spaces' rather than the actual test. Really not an elegant solution:
let attributes = [
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 16),
NSAttributedString.Key.backgroundColor : UIColor.red,
NSAttributedString.Key.foregroundColor : UIColor.white
]
let attributesBack = [
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 32),
NSAttributedString.Key.backgroundColor : UIColor.red,
NSAttributedString.Key.foregroundColor : UIColor.white
]
let line = " "
let text = "Hello World!"
line.draw(in: CGRect(x: 0, y: 0, width: 2000, height: 2000), withAttributes: attributesBack)
text.draw(in: CGRect(x: 0, y: 10, width: 2000, height: 2000), withAttributes: attributes)
Is Thera a way: a. To either set the CGRect the text is drawn in to spread across the whole page, like a Spacer()? b. A way to draw an actual rectangle and then draw the text on-top of that?