IOS Text Drawing for Clear Context

I have a simple application to which I have added a custom line chart. When drawing this diagram on my UIViews, everything is fine, but when I added the diagram to the simplified view, I suddenly feel a situation where all the text I am drawing is clear / not.

There are some static variables due to how animation (iOS / Android / Web) needs to be handled in the algorithm, so the complete example is rather complicated.

To explain this, I added a simple paint method at the end of my CALayer.draw

overrideenter image here

    //TEST CODE
    let box = CGRect(x: 0, y: 0, width: 100, height: 100)
    let textToDraw = "I AM A TEST"
    let font = UIFont.boldSystemFont(ofSize: 10)
    let boxSize = fontSize.space
    let paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.alignment = .right
    let attrs = [
        NSFontAttributeName: font,
        NSParagraphStyleAttributeName: paragraphStyle,
        NSForegroundColorAttributeName: UIColor.black
    ]


    ctx.setStrokeColor(UIColor.orange.cgColor)
    ctx.beginPath()
    ctx.move(to: CGPoint.zero)
    ctx.addLine(to: CGPoint(x: box.width, y: box.height))
    ctx.addLine(to: CGPoint(x: box.origin.x + box.width, y: box.origin.y + box.height))
    ctx.strokePath()

    //                print("fontSize:\(fontSize) string:\(textToDraw)")
    //textToDraw.draw(with: offset , options: .usesLineFragmentOrigin, attributes: attrs, context: nil)
    textToDraw.draw( in: box, withAttributes: attrs)

      

However, and it's frustrating if I'm in ANOTHER view that draws the diagram (or any other custom draws) I get this: enter image description here

I'm having trouble keeping track of this and have a (justifiably) annoyed client.

The code to "reload the view" is basically view.dismiss(animated:true)

and then performSegue("brokenView")

Has anyone encountered this behavior before? Are there any pointers you can suggest to get the text. I am at the point I am discussing about dropping a hidden UIView with a drawing on my main screen to fix this, but there must be a better way.

Orange lines were inserted to check that my "bounding boxes" were not on screen.

This layer is basically like this:

+3


source to share





All Articles