2013-07-20 130 views
3

有人请解释如何仅在最后一个单元格上创建一个或两个像素阴影(换句话说,我不想在整个tableview中使用阴影,只是在底部单元格什么我谈论的图像:为UITableView创建阴影

enter image description here

回答

2

解决。使用下面的代码在的底部产生一个非常漂亮的微妙阴影3210。使它看起来像它微微抬起了页面:)

UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(3, 49, cell.frame.size.width-26, 3)];/// change size as you need. 
     separatorLineView.backgroundColor = shadowColor;// you can also put image here 
     UIBezierPath *roundedShadow = [UIBezierPath bezierPathWithRoundedRect:separatorLineView.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(8.0f, 8.0f)]; 
     CAShapeLayer *newSeparatorShape = [[CAShapeLayer alloc] init]; 
     [newSeparatorShape setPath:roundedShadow.CGPath]; 

     separatorLineView.layer.mask = newSeparatorShape; 

     [cell.contentView addSubview:separatorLineView]; 

而且,不要忘了把这个在您的.m文件#import <QuartzCore/QuartzCore.h>

+1

我也试着用这个贝塞尔路径:) – KDeogharkar

+1

@BaZinga好男人,好:] – Apollo

+0

@BaZinga是的,现在,当你选择它使用你在最后一个问题的答案中描述的高亮技术时,阴影是失去了,所以只用贝塞尔路径来实现它可能会解决这个问题...... – Apollo

0

,你可以在的tableView:cellForIndexPath:细胞的背景图片设置为一个包括与阴影的圆角

+0

的顶部是真正的最佳方式,但?有没有办法与原生图形框架做到这一点? – Apollo