良好的 iOS 表格视图阴影(如时钟应用程序)

发布于 2024-11-27 09:14:16 字数 681 浏览 1 评论 0原文

我对 iOS 编码很陌生,我似乎找不到一个好的教程版本来告诉我如何有效地向表格视图添加阴影。

我尝试过(然后是其他一些随机的): http://cocoawithlove.com/2009/08/adding-shadow -effects-to-uitableview.html 根本不适合我,给了我错误。

http://www.iphonedevsdk.com/forum/iphone-sdk-development/5939-safari-like-uiwebview-uiscrollview-uitableview-beyond-bounds-gradient.html 尝试了核心显卡,效果很好,但在 iPhone 上速度很慢。只是不那么敏捷。我也尝试过图像,但看起来很糟糕。

有没有像默认时钟应用程序一样快捷的好版本?必须有一些“标准”。

I'm quite new to iOS coding and I can't seem to find a good tutorial version that tells me how to efficiently add shadows to table view.

I've tried (then some other random ones):
http://cocoawithlove.com/2009/08/adding-shadow-effects-to-uitableview.html
Didn't work for me at all, gave me errors.

http://www.iphonedevsdk.com/forum/iphone-sdk-development/5939-safari-like-uiwebview-uiscrollview-uitableview-beyond-bounds-gradient.html
Tried the core graphics one that worked perfectly but is very slow on the iPhone. It's just not snappy. I also tried images but it just looked bad.

Is there a good version that is snappy like in the default clock app? There has to be some "standard."

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

青瓷清茶倾城歌 2024-12-04 09:14:16

没有真正的标准,但 CAGradientLayer 在大多数情况下是正确的方法。您遇到了哪些错误?

There’s no real standard, but CAGradientLayer is the right approach in most cases. What errors were you encountering with it?

缪败 2024-12-04 09:14:16

Matt Drance 和 Paul Warren 所著的 iOS Recipes 书中的 Recipe 20“为表视图添加边框阴影”对此进行了介绍。该配方将阴影图像视图添加到 UITableView 子类中,并根据需要在 layoutSubviews 中重新定位。

我还使用阴影图像视图作为表页眉和页脚属性来完成此操作,但这有一个明显的缺点,即阻止您添加其他视图作为页眉和页脚视图。

This is covered in Recipe 20, "Add Border Shadows for Table Views," of the iOS Recipes book by Matt Drance and Paul Warren. The recipe adds shadow image views to a UITableView subclass which are repositioned as necessary in layoutSubviews.

I have also accomplished this using shadow image views as table header and footer properties, but this has the obvious downside of preventing you from adding other views as header and footer views.

不及他 2024-12-04 09:14:16

如果您不在表格视图中使用表格页眉和页脚,这里有一个非常简单的解决方案:

  1. 添加两个渐变视图(图像或带有渐变绘图的 UIView 子类)作为 tableHeaderView 和 tableFooterView。可以在 Interface Builder 中完成。
  2. 设置顶部和底部表格视图的内容插入底部到渐变视图的负高度。

您可以在此处找到此解决方案的代码示例: http://rowboatrevolution.com/ 2009/06/drop-shadows-in-uitableview/

If you don't use the table header and footer in your table view, here is a very simple solution:

  1. Add two gradient views (either images or subclasses of UIView with some gradient drawing) as tableHeaderView and tableFooterView. Can be done in Interface Builder.
  2. Set content inset of the table view for top & bottom to the negative height of the gradient views.

You can find code samples for this solution here: http://rowboatrevolution.com/2009/06/drop-shadows-in-uitableview/

温柔女人霸气范 2024-12-04 09:14:16

我只是能够通过一个小技巧在表格视图上获得内部阴影。

我在表格视图的顶部放置了一个 1px X 320px UIView,然后在这个视图周围放置了一个阴影,如下所示:

self.shadowWrapper.layer.shadowColor = [[UIColor blackColor] CGColor];
self.shadowWrapper.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
self.shadowWrapper.layer.shadowOpacity = .90f;
self.shadowWrapper.layer.shadowRadius = 3.0f;

在我的例子中,我的表格视图位于页面的一半位置,所以我使用另一个视图坐在我的“阴影”上方包装纸”并将阴影隐藏在阴影的顶部。这在我的表格视图的顶部留下了一个阴影,呈现出内部阴影的外观。

I was just able to get an inner shadow on a table view via a little trick.

I put a 1px X 320px UIView at the top of the table view and then put a shadow around this view like this:

self.shadowWrapper.layer.shadowColor = [[UIColor blackColor] CGColor];
self.shadowWrapper.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
self.shadowWrapper.layer.shadowOpacity = .90f;
self.shadowWrapper.layer.shadowRadius = 3.0f;

In my case I had my table view half way down the page, so I used another view to sit above my "shadow wrapper" and hide the shadow on the top side of my shadow. This left a shadow sitting over the top of my table view giving the appearance of an inner shadow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文