J'ai une cellule tableView, qui a une vue d'image. Pour cette vue, j'ai créé l'extension UIImage, où je dessine avec le rectangle bezierPath 2, puis, à partir de ce dessin, je crée une image.Comment faire des coins arrondis dans l'image qui a été dessinée avec 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!
}
Alors, quand je mets cette image dans une vue de l'image, les coins ne sont pas lisses, ils sont floues:
Pouvez-vous des conseils, comment faire face? merci d'avance!
merci beaucoup! – Melany
@Melany De rien. Codage heureux! – alexburtnik
J'utilise généralement 0 pour l'échelle, puisque le système détermine l'échelle de l'écran de l'appareil dans ce cas. –