围绕UITableView的一段阴影
我有一个UITableView
4节。 现在我想添加一个阴影效果到表的特定部分,而不是整个表。 我怎样才能做到这一点?
尝试这个
yourView.layer.shadowColor = [[UIColor blackColor] CGColor]; yourView.layer.shadowOffset = CGSizeMake(1.0f, 1.0f); yourView.layer.shadowRadius = 3.0f; yourView.layer.shadowOpacity = 1.0f;
你需要用其他东西replace“yourView”
不要忘了你还需要导入QuartzCore / CALayer.h
您将不得不改变部分页眉和页脚以及该部分的所有单元格。
使用tableView:viewForFooterInSection:
, tableView:viewForHeaderInSection:
和tableView:cellForRowAtIndexPath:
为此。 只需添加一个UIView与rgba 0/0/0 / 0.2或相似的每个视图,你想成为黑暗。
你可以添加阴影的图像作为UITableViewCell的背景。 应该在图像中绘制阴影。 这是非常简单的,你的应用程序将运行得更快。
您可以指定所需部分的阴影。 这里是一个例子。
首先,我们正在为您的标题提供一些空间
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if(section == mysection) { // Returns the height you want for the header section. I am giving 20 return 20; } }
然后是标题的装饰
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if(section == mysection) { UIView *shadowView = [[[UIView alloc] initWithFrame: CGRectMake(0,0,320,20)] autorelease]; shadowView.backgroundColor = [UIColor whiteColor]; // Doing the Decoration Part shadowView.layer.shadowColor = [[UIColor blackColor] CGColor]; shadowView.layer.shadowOffset = CGSizeMake(1.0f, 1.0f); shadowView.layer.shadowRadius = 3.0f; shadowView.layer.shadowOpacity = 1.0f; return shadowView; } return nil; }
完成它在你身边。 这是一个基本的大纲。 快乐编码:)