我有tableView cellForRowAtIndexPath
功能:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: ProjectCell = tableView.dequeueReusableCellWithIdentifier("Cell") as! ProjectCell
let rightUtilityButtons = NSMutableArray()
rightUtilityButtons.sw_addUtilityButtonWithColor(UIColor(red: 255.0/255.0, green: 200.0/255.0, blue: 122.0/255.0, alpha: 1.0), icon: UIImage(named: "ic_edit"))
rightUtilityButtons.sw_addUtilityButtonWithColor(UIColor(red: 255.0/255.0, green: 120.0/255.0, blue: 122.0/255.0, alpha: 1.0), icon: UIImage(named: "ic_close"))
cell.setRightUtilityButtons(rightUtilityButtons as [AnyObject], withButtonWidth: 70)
cell.delegate = self
let project = projects[indexPath.row] as! Project
cell.projectNameLabel.text = project.name
cell.projectDescriptionLabel.text = project.desc
cell.projectDateLabel.text = project.duedate
cell.customView.backgroundColor = getColor(indexPath.row * 10)
cell.backView.layer.cornerRadius = 6
cell.backView.layer.shadowColor = UIColor.blackColor().CGColor
cell.backView.layer.shadowOffset = CGSize(width: -1, height: 1)
cell.backView.layer.shadowOpacity = 0.5
return cell
}
问题在于:
cell.backView.layer.shadowColor = UIColor.blackColor().CGColor
cell.backView.layer.shadowOffset = CGSize(width: -1, height: 1)
cell.backView.layer.shadowOpacity = 0.5
如果没有此代码,我的表视图效果很好。如何解决这个问题呢。也许更好的地方我的单元格视图将是willDisplayCell,但如何把这些代码放在那里?
答案 0 :(得分:1)
将设置阴影的代码移动到单元格的初始化。现在,每次委托将单元格返回到表视图时都会设置阴影。您不必为刚刚重复使用且已配置阴影的单元格执行此操作。
请记住在处理阴影时设置shadowPath
。它提高了性能。
[view.layer setShadowPath:[[UIBezierPath bezierPathWithRect:view.bounds] CGPath]];
答案 1 :(得分:0)
您可以尝试下一步来改善阴影效果:
shouldRasterize
CALayer
属性对您的图层进行栅格化(您还应将rasterizationScale
属性设置为UIScreen.mainScreen().scale
)shadowPath
的{{1}}属性代替CALayer
,如下所示:_
shadowOffset
作为替代方法,您可以在单元格下方使用可调整大小的透明图像。