I was trying to follow a tutorial on CoreText and how to draw the text, and I implemented this function in my customView.
override func draw(_ rect: CGRect) {
guard let context = UIGraphicsGetCurrentContext() else { return }
let path = CGMutablePath()
path.addRect(bounds)
let attrString = NSAttributedString(string: "Hello World")
let framesetter = CTFramesetterCreateWithAttributedString(attrString as CFAttributedString)
let frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, attrString.length), path, nil)
CTFrameDraw(frame, context)
}
It works fine when the text is short but when the text becomes more than 10k letters, it renders in a wrong way. Is there any solution for that?
NOTE: this happen when the text in Arabic not English.
Here is the render when the text is small:
Here is the text render when the text count is too big above 10kb, it appears disjointed and reversed:
attrString.draw(in: rect)
instead of Core Text will work here, but I get that you want to learn CT) – Bellbird