iOS7-UItableViewCell 以 Grouped 样式显示在表格 View 中

标签 ios7

在 iOS7 中,分组 TableView 的单元格显示为 TableView 的全宽,更像是普通 TableView 样式。但在模拟器的设置应用程序中,分组样式看起来不同。对于实现这种类型的单元有什么帮助吗?

最佳答案

此解决方案适用于 iOS7 以及以前版本的 iOS。

创建自定义 UITableView 单元格类并覆盖 UITableViewCell。在 setFrame 中您可以调整所需的单元格大小。 setFrame 和 setAlpha 都是在 tableView:willDisplayCell:forRowAtIndexPath: 之后调用的,因此任何辅助 View 和 ImageView 都可以正确显示。

引用:https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewDelegate_Protocol/#//apple_ref/occ/intfm/UITableViewDelegate/tableView:willDisplayCell:forRowAtIndexPath :

@interface CustomTableViewCell : UITableViewCell

@end

@implementation CustomTableViewCell

-(void) setFrame:(CGRect)frame
{
  float inset = 20.0f;
  frame.origin.x += inset;
  frame.size.width -= 2 * inset;
  [super setFrame:frame];
}
@end

在 cellForRowAtIndexPath 中,将 UITableViewCell 替换为 CustomTableViewCell。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomTableViewCell *cell =  [tableView dequeueReusableCellWithIdentifier:@"CustomTableViewCell" forIndexPath:indexPath];

...

}

在 Storyboard文件中将原型(prototype)单元格类设置为CustomTableViewCell,并将其标识符设置为“CustomTableViewCell”

IndentedGroupedTableViewCell

关于iOS7-UItableViewCell 以 Grouped 样式显示在表格 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18783270/

相关文章:

ios - 将选择器传递给自定义方法以编程方式创建 UIButton

html - iO7 上的 Safari CSS 背景大小问题

ios - 如何非公开启动 iPhone 应用程序?

ios - 从 UITableView 中去掉左边的空间

memory - 当我的 iOS 游戏进入后台模式时,它是否应该释放内存?

ios - XCode iOS7 - 带有 UITextView 的动态单元格(如提醒应用程序)

ios - 具有可选择日期范围的日历

c# - 在 iOS 7 中获取字符串的大小

ios - 白色背景显示在 iOS 7 的搜索栏上方

ios - ChromeCast 音频播放器重新定位自身