gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 17:32:03 24 4
gpt4 key购买 nike

在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com