I am attempting to draw text to a UIView using CATextLayer and so far nothing is showing up. I must be missing something simple.
private func drawText(string: String, at: CGPoint, withFont: CGFont, fontColor: CGColor, fontSize: CGFloat) -> CATextLayer {
let textLayer = CATextLayer()
textLayer.string = string
textLayer.font = withFont
textLayer.fontSize = fontSize
textLayer.alignmentMode = .center
textLayer.contentsScale = UIScreen.main.scale
textLayer.position = at
return textLayer
}
Function Calls
let string = String(increment * Double(6 - i))
let textLayer = drawText(string: string, at: CGPoint(x: 30, y: CGFloat((i * 19) + 18)), withFont: someCGFont, fontColor: UIColor.black.cgColor, fontSize: 10)
chart.layer.addSublayer(textLayer)
You're not setting the
CALayer
frame, check this test source and customize as per your requirement: