1
拉我有一個的tableView細胞,具有圖像視圖。 對於該視圖我創建的UIImage延伸,其中我正在與bezierPath 2矩形繪製,然後,從該圖我作出的圖像。如何使圓角的圖像,將其與BezierPath
class func drawTwoRectangles(_ frameOne: CGRect, frameTwo: CGRect, frameColor: UIColor) -> UIImage {
UIGraphicsBeginImageContext(CGSize(width: frameOne.size.width, height: frameOne.size.height))
let context = UIGraphicsGetCurrentContext()
UIColor(red: 0/255.0, green: 153/255.0, blue: 216/255.0, alpha: 1.0).setFill()
let bpath:UIBezierPath = UIBezierPath(roundedRect:CGRect(origin: CGPoint(x:1, y:1), size: CGSize(width: frameOne.size.width - 2, height: frameOne.size.height - 2)), byRoundingCorners: [.allCorners], cornerRadii: CGSize(width: 5, height: 5))
bpath.lineCapStyle = .round
bpath.lineJoinStyle = .round
bpath.close()
bpath.fill()
UIColor.white.setFill()
UIColor.white.setStroke()
let bpathTwo:UIBezierPath = UIBezierPath(rect: frameTwo)
bpathTwo.close()
bpathTwo.fill()
bpathTwo.stroke()
frameColor.setStroke()
let bpathThree:UIBezierPath = UIBezierPath(roundedRect: CGRect(origin: CGPoint(x:1, y:1), size: CGSize(width: frameOne.size.width - 2, height: frameOne.size.height - 2)), cornerRadius: 5)
bpathThree.lineWidth = 2
bpathThree.close()
bpathThree.stroke()
bpath.append(bpathTwo)
bpath.append(bpathThree)
context?.addPath(bpath.cgPath)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}
所以,當我設置的圖像轉換爲圖像視圖,邊角不光滑,它們是模糊的:
請您諮詢,如何處理呢? 在此先感謝!與此
UIGraphicsBeginImageContext(CGSize(width: frameOne.size.width, height: frameOne.size.height))
:
非常感謝你,非常!!!! – Melany
@Melany不客氣。快樂的編碼! – alexburtnik
我通常使用0的規模,因爲該系統計算出在該情況下,設備的屏幕的比例。 –