2016-11-07 16 views
0

在watchOS我用下面的代碼畫了一個圈:在watchOS上的核心圖形莫爾效應?

// Create a graphics context 
UIGraphicsBeginImageContext(CGSize.init(width: 18.0, height: 18.0)) 
let context = UIGraphicsGetCurrentContext() 

// Draw a circle 
let rect = CGRect.init(x: 1.0, y: 1.0, width: 16.0, height: 16.0) 
let border = UIBezierPath(ovalIn: rect) 
border.lineWidth = 1.0 
UIColor.white.setStroke() 
border.stroke() 

// Convert to UIImage 
let cgimage = context!.makeImage(); 
let uiimage = UIImage(cgImage: cgimage!) 

// End the graphics context 
UIGraphicsEndImageContext() 

的畫圓,但它看起來醜陋,因爲如果有一個條紋圖形,看圖片,留下了「XX」的文字:
enter image description here
應該可以避免這種模式,並畫出一個乾淨的圓圈,因爲時間也顯示清晰。但是如何?

回答

1

UIGraphicsBeginImageContext創建一個繪製比例爲1的上下文。換句話說,它是非視網膜。

嘗試

UIGraphicsBeginImageContextWithOptions(CGSize.init(width: 18.0, height: 18.0), false, 0) 

的屏幕比例定爲0,使得它默認爲當前屏幕比例更換

UIGraphicsBeginImageContext(CGSize.init(width: 18.0, height: 18.0)) 

。讓我知道如果這不起作用。 :)

+0

太棒了,它的工作原理。圓的直徑現在是現在的兩倍,但這肯定只是一個縮放問題。非常感謝! –