Tun*_*dır 3 uiimageview ios uicollectionview swift swift4
我在UICollectionView Cell中有一个UIImageView,我想让它的顶角变圆.我无法解决,任何帮助都表示赞赏.
你可以看到单元格有10px的角半径,我也希望在图像上应用相同的效果.
Ash*_*iya 14
这里我的自定义类AGRoundCornersView
extension UIImageView {
public func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let maskPath = UIBezierPath(roundedRect: bounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))
let shape = CAShapeLayer()
shape.path = maskPath.cgPath
layer.mask = shape
}
}
Run Code Online (Sandbox Code Playgroud)
代码:
1.调整视图大小时调用.
uiimage.roundCorners([.topLeft, .topRight], radius: 10)
Run Code Online (Sandbox Code Playgroud)
2.创建自定义类
class CustomImageView: UIImageView {
override func layoutSubviews() {
super.layoutSubviews()
self.roundCorners([.topLeft, .topRight], radius: 10)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2175 次 |
| 最近记录: |