在 swift 5

问题描述 投票:0回答:0

enter image description hereenter image description here

我想在 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.
ios swift user-interface uicollectionview cellspacing
© www.soinside.com 2019 - 2024. All rights reserved.