ios - TableView ContentInset 不缩小单元格宽度/向 TableView 内容添加水平填充

标签 ios objective-c uitableview ios7 padding

我想要一个全屏的 UITableView。但是 UITableView 的内容应该在左边和右边有一个填充。

所以我尝试设置ContentInset。但现在单元格与 UITableView 一样宽,并且 UITableView 水平滚动。

有没有办法说 UITableView 内容的宽度应该被水平内容插入变窄?还是我必须向所有单元格和页眉/页脚 View 添加填充?

我不想缩小 TableView 本身,因为滚动指示器应该位于屏幕的右侧而不是中间。 这里(How to set the width of a cell in a UITableView in grouped style)建议的解决方案似乎不像我喜欢的那样通用,因为单元格和页眉和页脚 View 必须知道填充(至少要维护 3 个位置而不是一个)

最佳答案

I don't want to narrow the table view itself, because the scroll indicator should stay at the right side of the screen and not in the middle.

这让你开心?

_tableView.clipsToBounds = NO;
_tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -30.f);

如果您不喜欢 clipsToBounds = NO 效果,您可以将 tableView 嵌入到 clipsToBounds = YES 的容器 View 中。

关于ios - TableView ContentInset 不缩小单元格宽度/向 TableView 内容添加水平填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24882525/

相关文章:

ios - 如何在不影响行间距的情况下截断 UILabel?

IOS Sinch Calling when Application is offline using APN(Get previously initiated Client)

ios - 无效 token VoIP Apple 推送通知

ios - 什么是iOS 7中UDID或UUID的副本

ios - 锁定和解锁手机后更新 UIView

objective-c - NSNotificationCenter 作用域定义

objective-c - 如何在网络出现故障时使用 MKNetworkKit 恢复下载

ios - UITableView 自定义单元格点击文本字段时自动滚动 : Swift 3

swift - 单击取消按钮时隐藏 TableView

ios - 隐藏单个 UITableViewCell 分隔符