【发布时间】:2017-02-23 14:46:22
【问题描述】:
我有一个 tableView 单元格,它有一个图像视图。 对于这个视图,我创建了 UIImage 扩展,我在其中使用 bezierPath 2 矩形进行绘制,然后,从这个绘图中我制作了一个图像。
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!
}
所以当我将此图像设置为 Image 视图时,角落不平滑,它们被模糊:
您能建议一下,如何处理吗? 提前致谢!
【问题讨论】:
标签: ios swift uiimageview uiimage uibezierpath