内部自定义UIView
,我已经覆盖draw()
函数。我需要在圆形布局中绘制图像。另外,如果可能的话,我需要调整图片的大小以保持方面的填充/适合属性。怎么做?如何在Core Graphics上绘制圆形UIImage
代码:
@IBDesignable class ScoreGraphView: UIView {
override func draw(_ rect: CGRect) {
let iv = UIImageView(image: UIImage(named: "women"))
iv.frame = CGRect(x: 0, y: 0, width: rect.width, height: rect.height)
iv.layer.cornerRadius = 20
iv.clipsToBounds = true
iv.layer.masksToBounds = true
iv.backgroundColor = UIColor.clear
iv.draw(CGRect(x: 0, y: 0, width: rect.width, height: rect.height))
}
}
这上面的行可以用于绘制图像。 cornerRadius
/masksToBounds
不起作用。
在此先感谢!
'cornerRadius'只有在你设置了'masksToBounds = true'的情况下才有效 – Tj3n
@ Tj3n你的意思是clipToBounds = true?我也尝试过,但没有运气。 –
'iv.layer.masksToBounds = true'不起作用?它对我来说工作得很好,也许在你的'draw'函数中你重写了一些东西? – Tj3n