良好的 iOS 表格视图阴影(如时钟应用程序)
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
没有真正的标准,但 CAGradientLayer 在大多数情况下是正确的方法。您遇到了哪些错误?
There’s no real standard, but CAGradientLayer is the right approach in most cases. What errors were you encountering with it?
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.
如果您不在表格视图中使用表格页眉和页脚,这里有一个非常简单的解决方案:
您可以在此处找到此解决方案的代码示例: 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:
You can find code samples for this solution here: http://rowboatrevolution.com/2009/06/drop-shadows-in-uitableview/
我只是能够通过一个小技巧在表格视图上获得内部阴影。
我在表格视图的顶部放置了一个 1px X 320px UIView,然后在这个视图周围放置了一个阴影,如下所示:
在我的例子中,我的表格视图位于页面的一半位置,所以我使用另一个视图坐在我的“阴影”上方包装纸”并将阴影隐藏在阴影的顶部。这在我的表格视图的顶部留下了一个阴影,呈现出内部阴影的外观。
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:
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.