如何在 Swift 中向集合视图添加边框?

Chr*_*Chu 0 ios swift

不是集合视图单元格,我通过在 ViewController 中应用特定的边框函数(例如 borderColor 和cornerRadius 方法)来解决这个问题。我说的是用一个边框封装单元格的整个视图,有点像这样:

我想要实现的集合视图单元格

非常感激。

elk*_*ner 5

在你的 ViewDidLoad 函数中,只需添加这种类型的行(选择你的值)。

collectionView.layer.borderColor = UIColor.green.cgColor
collectionView.layer.borderWidth = 3.0
collectionView.layer.cornerRadius = 3.0//if you want corner radius.addtional
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述