UITableView ContentInsets 水平滚动内容 [英] UITableView ContentInsets scrolling content horizontally

查看:45
本文介绍了UITableView ContentInsets 水平滚动内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一些左边的空间,10 像素,给 UITablViewcCell.我在下面编写代码,但它的滚动内容是水平滚动的.我不想要那个.

i want some left space, 10 pixels, to UITablViewcCell. I write code below but its scrolling content horizontally. I dont want that.

self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 130.0, 768.0)];
    self.horizontalTableView.contentInset = UIEdgeInsetsMake(0.0, 10.0, 0.0, 0.0);

我是否需要使用contentOffset contentSize tableview 的属性.

Do i need to use contentOffset contentSize property of tableview.

推荐答案

我认为最好的解决方案是创建子类 UITableViewCell 并在 layoutSubviews 方法中设置其子视图的框架以满足您的间距要求.这将更加清洁和可扩展.仔细查看 tableview 单元格 是一个很好的阅读.

I think the best solution is to create subclass UITableViewCell and set the frames of its subiews in layoutSubviews method to suit your spacing requirements. This will be lot cleaner and extendible. A closer look at tableview cells is a good read for this.

但是也有一些捷径,每个都有自己的缺点:

But there are some short-cuts towards this as well, each with its own disadvantages:

  1. 设置单元格缩进

  1. Set indentation for cells

-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath

此方法将为您的单元格内容(左边距)添加缩进.但是单元格分隔符将占用单元格的实际宽度,即表格宽度.因此,您需要将分隔符样式设置为无,这样就不会显示它.但如果您需要单元格分隔符,则不适用.

This method will add indentation to your cell contents (left margins). But the cell separator will occupy the actual width of the cell, i.e the table width. So you'll need to set the separator style to none, so that it is won't be shown. But not applicable if you need a cell separator.

减小整个tableViews框架尺寸

Reduce the entire tableViews frame size

这是最简单的方法,也很明显,但是当您需要在单元格和 tableView 之间留出边距时它就显得很蹩脚了.

This is the easiest way and quite obvious, but its lame when you require a margin between cell and the tableView.

在设置contentInset时,您应该已经注意到文档.

As you have done it, setting contentInset, you should have noticed the discussion about it in Docs.

使用此属性添加到内容周围的滚动区域.大小的单位是点.默认值为 UIEdgeInsetsZero.

Use this property to add to the scrolling area around the content. The unit of size is points. The default value is UIEdgeInsetsZero.

我认为使用 contentOffset 和 contentSize 将有助于实现边距,但对我来说,更改这些值从来没有任何效果.可能正如安德烈所说,它们可能在内部进行管理.但我很想听到更多关于这些属性及其反映的行为的信息.

I thought playing with contentOffset and contentSize would help achieve margins, but for me changing the values never had any effect. Probably as Andrey said, they might be managed internally. But I would love to hear more about these properties and their reflected behaviors.

编辑

contentOffset 和 contentSize 继承自 UIScrollView,在 UITableView 中的含义相同,因为它是 UIScrollView 的子类.

contentOffset and contentSize are inherited from UIScrollView and means same in UITableView as it a subclass of UIScrollView.

这篇关于UITableView ContentInsets 水平滚动内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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