UITableViewCell阴影 [英] UITableViewCell shadows
问题描述
我正在尝试实现这个设计,但我浏览过的所有解决方案都无法正常工作,因为单元格和UITableView之间的间距可能是我所理解的。
这是设计:
I'm trying to implement this design but all solutions I have browsed won't work and from what I understand it could be because of the spacing between the cells and the UITableView.
Here's the design:
所以基本上我正在尝试要实现的是从所有4个边都有阴影,以及每个细胞和下面的细胞之间有一些间距。
谢谢
So basically what I'm trying to achieve is to have shadows from all 4 sides as well as some spacing between each cell and the following cell. Thanks
编辑:
这是我试过的代码。
Here's the code I tried.
let shadowSize : CGFloat = 5.0
let shadowPath = UIBezierPath(rect: CGRect(x: -shadowSize / 2,
y: -shadowSize / 2,
width: self.avatarImageView.frame.size.width + shadowSize,
height: self.avatarImageView.frame.size.height + shadowSize))
self.avatarImageView.layer.masksToBounds = false
self.avatarImageView.layer.shadowColor = UIColor.black.cgColor
self.avatarImageView.layer.shadowOffset = CGSize(width: 0.0, height: 0.0)
self.avatarImageView.layer.shadowOpacity = 0.5
self.avatarImageView.layer.shadowPath = shadowPath.cgPath
编辑2:
我想指出我所有单元格的对象都在容器UIView中。以上所有代码都适用于此UIView。
Edit 2: I'd like to point out that all my cell's objects are inside a container UIView. All the above code is applied to this UIView.
推荐答案
您必须制作 UIView
里面 UITableViewCell
并处理该视图。
You have to make a UIView
inside UITableViewCell
and work on that view.
对于我在 UITableViewCell使用的阴影
CLASS: -
FOR SHADOW I AM USING THIS IN UITableViewCell
CLASS:-
viewDummy.addShadow() //use from any view
extension UIView {
func addShadow(){
self.layer.shadowColor = UIColor.blackColor().CGColor
self.layer.shadowOpacity = 0.5
self.layer.shadowRadius = 2.0
self.layer.shadowOffset = CGSizeMake(1.0, 1.0)
}
}
这篇关于UITableViewCell阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!