我創建了一個collectionView
,我想陰影添加到每一個細胞,我寫了這個代碼陰影不會出現在collectionViewcell
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! MyCollectionViewCell
cell.myLabel.text = self.items[indexPath.item]
cell.backgroundColor = UIColor.yellow
cell.layer.shadowColor = UIColor.black.cgColor
cell.layer.shadowOffset = CGSize(width: 3, height: 3)
cell.layer.shadowOpacity = 0.7
cell.layer.shadowRadius = 4.0
return cell
}
但這是輸出
我想它是這樣的 UIView with rounded corners and drop shadow?
如果你說'cell.layer.masksToBounds = false',會有幫助嗎? – matt
@matt它的工作!謝謝 – amjad
這很好,我會給它作爲答案。 – matt