将自定义视图放入UITableView [英] Putting a custom view into a UITableView

查看:88
本文介绍了将自定义视图放入UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个普通风格的UITableView - 一个有白色背景和灰色水平线分隔行。

I have a regular-style UITableView—the one that has a white background and gray horizontal lines to separate the rows.

我有另一个自定义UIView一个100x100的redColor矩形。

I have another custom UIView that is just a 100x100 rectangle filled with redColor.

如何将后者放入前者,使其在水平线上显示 仍然是表视图的部分,意思是当我滚动表视图周围时,红色视图滚动吗?事实上,我也应该能够把我的手指放在红色区域并滚动表视图。

How can I put the latter into the former, such that it appears over the horizontal lines, but is still a "part" of the table view in the sense that when I scroll the table view around, the red view scrolls with it? In fact, I should also be able to put my finger on the red area and scroll the table view.

再次,如果红色视图被放置为重叠一些水平线,则应显示超过行。可悲的是,当我只是将红色视图作为子视图添加到表视图中时,水平线会超过红色视图;请参阅此屏幕截图

Once again, if the red view is placed to overlap some horizontal lines, it should appear over the lines. Sadly, when I just add the red view as a subview to the table view, the horizontal lines go over the red view; see this screenshot.

如何实现?

推荐答案

EDIT

你试图添加视图a上面的行(隐藏线)尝试使用 - bringSubviewToFront:将它带到表视图的前面。

If you are trying to add the view a above the lines (hide the lines) try to use – bringSubviewToFront: to take it to the front of the table view.

[self.tableView bringSubviewToFront:redView];

ELSE

将视图添加到 self.tableView.tableHeaderView 这将放置在表视图上方,并将滚动与表视图。

Add the view to the self.tableView.tableHeaderView this will place it above the table view and will scroll with the table view.

UIView *redView = [[UIView alloc]init];
  redView.frame = //set the frame 
  redView.backgroundColor = [UIColor redColor];
  self.tableView.tableHeaderView = redView;

祝你好运

这篇关于将自定义视图放入UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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