在 iOS7 中,分组表视图的单元格显示为表视图的全宽,更像是普通表视图样式。但在模拟器的设置应用程序中,分组样式看起来不同。对于实现这种类型的单元有什么帮助吗?
该解决方案适用于 iOS7 以及以前版本的 iOS。
创建自定义 UITableView 单元格类并覆盖 UITableViewCell。在 setFrame 中您可以调整所需的单元格大小。 setFrame 和 setAlpha 都是在 tableView:willDisplayCell:forRowAtIndexPath: 之后调用的,因此任何辅助视图和图像视图都可以正确显示。
参考 :https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewDelegate_Protocol/#//apple_ref/occ/intfm/UITableViewDelegate/tableView:willDisplayCell:forRowAtIndexPath 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];
...
}
在故事板文件中将原型单元类设置为自定义 TableView 单元格它是标识符“自定义TableView单元格”
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)