我想在 swift 的集合视图的单元格中制作一条灰色的边框线
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
selectedIndexPath = indexPath
}
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
var borderColor: CGColor! = UIColor.clear.cgColor
var borderWidth: CGFloat = 0
if indexPath == selectedIndexPath{
borderColor = UIColor.brown.cgColor
borderWidth = 1 //or whatever you please
}else{
borderColor = UIColor.clear.cgColor
borderWidth = 0
}
cell.layer.borderWidth = borderWidth //You can use your component
cell.layer.borderColor = borderColor
}
I tried this way.