I'm doing custom drawing in view. It basically just draws a circle. I need text to appear in the middle of that circle. I tried using stringToDraw method, but it aligns my text to the frame origination point. Is there a way to align?
override func draw(_ rect: CGRect) {
let arcCenter = CGPoint(x:bounds.size.width/2,y:bounds.size.height/2)
let halfSize:CGFloat = min( bounds.size.width/2, bounds.size.height/2)
let desiredLineWidth:CGFloat = 1 // your desired value
let circlePath = UIBezierPath(
arcCenter: arcCenter,
radius: CGFloat( halfSize - (1/2) ),
startAngle: CGFloat(0),
endAngle:CGFloat(CGFloat.pi * 2),
clockwise: true)
circlePath.lineWidth = desiredLineWidth
circlePath.stroke()
let stringToDraw = "Text" as NSString
let rectToDraw = bounds
stringToDraw.draw(in: rectToDraw)
}