UITableView自定义标题(如FoodSpotting应用程序) [英] UITableView custom header (like FoodSpotting app)

查看:104
本文介绍了UITableView自定义标题(如FoodSpotting应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释这个应用程序(FoodSpotting)如何创建自定义节标题?它有一个半透明的黑色背景,用户的图像,以及一些不错的文本(毫无疑问从服务器加载)。我的两大问题是:

Could somebody explain how this app (FoodSpotting), creates their custom section header? It has a translucent black background, image of the user, and some nice text (loaded up from a server no doubt). My 2 big questions here are:

1。该应用如何在部分标题上获得漂亮的黑色半透明效果?
2。他们如何获得标题附加的小三角箭?

我可以基于使用节标题的自定义视图来弄清楚其他所有内容。

I can pretty much figure out everything else based on using a custom view for the section header.

推荐答案

节标题是一个UIView ,就像任何其他标题一样。您可以根据需要使用Interface Builder创建它美观,复杂或精细,等等。您的表委托的 tableView:viewForheaderInSection 负责返回它,就像它用于其他单元格行一样。

The Section header is a UIView just like any other. You can create it as beautiful, as complex, or as elaboarate as you like, using Interface Builder if you want, etc. Your table delegate's tableView:viewForheaderInSection is responsible for returning it, just like it is for other cell rows.

关于小三角形:是的,这让我们感到有点兴奋(我们希望在我们的应用程序中有类似的东西),直到我们发现你可以通过躺着它的高度来重叠视图和行:即 tableView:heightForHeaderInSection:返回的值略小于实际值。可能不是正确的方式,但对我们来说非常好。像这样:

As to the little triangle: yeah, this threw us for a bit (we wanted something similar in our app) until we discovered that you can overlap the view with the row by "lying" about it's height: ie tableView:heightForHeaderInSection: returns a value slight less than it actually is. May not be the "right" way, but worked very nicely for us. Like this:

所以标题实际上是一个完美的矩形,大部分是透明的底部,有一个小的三角形偷看:

So the header is actually a perfect rectangle, mostly see-through at the bottom, with a small triangle "peeking" out:

Tell标题为80px高的iOS,如下所示:

Tell iOS that the header is 80px high, like this:

- (CGFloat) tableView:(UITableView *) tableView 
  heightForHeaderInSection:(NSInteger) section {
    return 80;
  }

它将开始绘制80px的食物行。因为标题位于顶部,并且因为大多数标题底部是透明的,除了箭头,你应该得到这种效果。

and it’ll start to draw the "food" row at 80px. Because headers are on top, and because most of header bottom is transparent except for arrow, you should get this effect.

这篇关于UITableView自定义标题(如FoodSpotting应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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