2017-02-25 1 views

Répondre

0

écrire ci-dessous le code dans cellForRowAt indexPath

cell.contentView.layer.cornerRadius = 10 
cell.contentView.layer.shadowColor = UIColor.blue.cgColor 
cell.contentView.layer.shadowRadius = 3 
cell.contentView.layer.shadowOpacity = 1.0     
cell.contentView.clipsToBounds = true 
+0

Celui-ci ne fonctionne pas ... dès que vous faites 'cell.contentView.clipsToBounds = true' l'ombre disparaîtra. Coins arrondis? oui, Shadow? non. – Annjawn

4

Pour les deux l'ombre et les coins arrondis, vous pouvez utiliser ce code:

override func tableView(_ tableView: UICollectionView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    let cell = tableView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) 
    cell.layer.cornerRadius = 10 
    let shadowPath2 = UIBezierPath(rect: cell.bounds) 
    cell.layer.masksToBounds = false 
    cell.layer.shadowColor = UIColor.black.cgColor 
    cell.layer.shadowOffset = CGSize(width: CGFloat(1.0), height: CGFloat(3.0)) 
    cell.layer.shadowOpacity = 0.5 
    cell.layer.shadowPath = shadowPath2.cgPath 
    return cell 
} 

Et vous pouvez ajuster les valeurs et vous obtiendrez l'ombre parfaite pour vous!

J'espère que ça aide!