Search code examples
swiftgeometryuiimagewatchkitsmoothing

Appearance of drawn circle on the apple watch is not smooth enough. How can I do it better?


One approach I tried is the following:

let circle = Circle.init()
let path = circle.path(in: kServiceRightFrame)
let serviceRightPath = UIBezierPath.init(cgPath: path.cgPath)
serviceRightPath.lineWidth = 2.0
serviceRightPath.fill()
serviceRightPath.stroke()

enter image description here

I played around with flatness too, but that did not get the job done either. How can a smoother looking circle be drawn programmatically?

EDIT:A more extensive view of my code:

 UIGraphicsBeginImageContext(kWatchInterfaceSize)
 let context = UIGraphicsGetCurrentContext()

 //draw service path
 kSBScoreLabelFontColor.setStroke()
 kSBServiceBallColor.setFill()
 ---> code from above
    
 // Convert to UIImage
 let cgimage = context!.makeImage()
    
 //create scoreboardimage
 let scoreBoardImage = UIImage(cgImage: cgimage!)
    
  // End the graphics context'
  UIGraphicsEndImageContext() 

Solution

  • George put me on the right track. It was a scaling issue. The code that I changed was the following:

    //Replaced this
    //UIGraphicsBeginImageContext(kWatchInterfaceSize) 
    //with this
    UIGraphicsBeginImageContextWithOptions(kWatchInterfaceSize, 
    false, 4.0)
    

    That fixed it. Now the circle looks a lot smoother in appearance. enter image description here