Imagine that I have the text: "Some attribute of the text in the trapezoid."
I have an NSAttributedString extension that returns me a UIImage with a text attribute:
extension NSAttributedString {
func asImage() -> UIImage? {
defer {
UIGraphicsEndImageContext()
}
let size = boundingRect(with: CGSize.zero, options: [.usesLineFragmentOrigin, .truncatesLastVisibleLine], context: nil).size
UIGraphicsBeginImageContext(size)
draw(at: CGPoint.zero)
return UIGraphicsGetImageFromCurrentImageContext()
}
}
But this function returns me text in one line due to use boundingRect:
|Some attributed text in trapezoid.|
If I used a custom rectangle to draw text, that didn't help much ...
UIGraphicsBeginImageContext(CGRect(x: 0, y: 0, width: 100, height: 30))
draw(at: CGPoint.zero)
... because the text will be in a rectangle:
--------------
|Some attribu|
|ted text in |
|trapezoid. |
--------------
What I need is to draw text in a trapezoid with known angular positions (or in a circle with a known radius). Therefore, each new line of text should begin with a slight offset, see Example:

So, I want to see something like this:
---------------
\Some attribut/
\ed text in /
\trapezoid/
---------
How can I achieve this result?