我有一个CollectionViewController,我想将角半径设置为CollectionView(标题视图下方的部分)。
这就是我想要的(角半径为黄色)。可能吗?你对我怎么做到这一点有什么想法吗?
extension UICollectionView {
func roundCorners(_ corners:UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}}
collectioniew.roundCorners([.topLeft,.topRight], radius: 5)
解决方案非常简单。我刚刚删除了collectionViewLayout顶部的插图,并为HeaderView添加了一个新视图。之后,我将角半径应用到添加的视图中并且工作了:)