iPhone UITableViewCell图层阴影 [英] iPhone UITableViewCell layer shadow

查看:182
本文介绍了iPhone UITableViewCell图层阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用layer.shadowColor,Offset,Radius向UITableViewCell添加阴影,但它似乎不会以任何方式影响它。该表是分组样式。有什么想法吗?

I'm trying to add a shadow to a UITableViewCell using the layer.shadowColor, Offset, Radius but it doesn't seem to affect it in any way. The table is grouped style. Any ideas why?

这是我正在使用的代码:

Here is the code i'm using:

cell.layer.shadowColor= [UIColor blackColor].CGColor;
cell.layer.shadowRadius = 5.0;
cell.layer.shadowOffset = CGSizeMake(10, 10);


推荐答案

您还需要设置阴影不透明度,默认为为0,如果没有明确设置,你将看不到任何东西。

You need to also set the shadow opacity, it defaults to 0 and you won't see anything if you don't explicitly set it.

CALayer Reference

cell.layer.shadowOffset = CGSizeMake(1, 0);
cell.layer.shadowColor = [[UIColor blackColor] CGColor];
cell.layer.shadowRadius = 5;
cell.layer.shadowOpacity = .25;

另请注意,如果您没有设置阴影路径,iPhone上的性能会很糟糕/ iPad的。使用类似下面的代码来设置阴影路径,它不需要模糊tableviewcell下面的图层来创建高质量阴影。

Also note, that if you don't set the shadow path you will have terrible performance on the iPhone/iPad. Use something like the following code to set a shadow path, it removes the need to blur the layers underneath your tableviewcell's to create a "high quality" shadow.

CGRect shadowFrame = cell.layer.bounds;
CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:shadowFrame].CGPath;
cell.layer.shadowPath = shadowPath;

观看视频425(也是424和426)以了解更多关于WWDC 2010视频的信息: WWDC 2010会话视频

Watch video 425 (also 424 and 426) to learn more about shadows from the WWDC 2010 Videos available here: WWDC 2010 Session Videos

这篇关于iPhone UITableViewCell图层阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆