2017-02-25 178 views

回答

0

寫下面的代碼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

這一個不行......只要你做了'cell.contentView.clipsToBounds = true',陰影就會消失。圓角?是的,影子?沒有。 – Annjawn

4

對於陰影和圓角兩個,你可以使用此代碼:

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 
} 

而且可以調整值,你會得到對你來說完美的影子!

希望它有幫助!