我正在尝试为我的 collectionView 单元格创建自定义 selectedBackgroundView。我将 UIView 子类化,这是我的 drawRect 实现:
override func drawRect(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context)
let bezierPath = UIBezierPath(roundedRect: rect, cornerRadius: 5.0)
bezierPath.lineWidth = 5
let color = UIColor(red: 0, green: 0, blue: 0, alpha: 0)
color.setStroke()
UIColor(red:0.529, green:0.808, blue:0.922, alpha:1).setFill()
bezierPath.fill()
bezierPath.stroke()
CGContextRestoreGState(context)
}
下图描述了选中单元格时我得到的结果。
正如你所看到的,我得到了这个丑陋的黑角。我希望黑角完全透明。我怎样才能做到这一点?感谢您的帮助。
最佳答案
您可以将 View 层的角半径设置为 5。
self.view.layer.cornerRadius = 5;
并将 View 的 clipsToBounds 属性设置为 true。
self.view.clipsToBounds = true;
关于ios - 带有圆角的自定义 uicollectionViewCell selectedBackgroundView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31439646/