在 iOS 设备上,UITableView 中的部分标题具有良好的行为,当您滚动浏览部分时,它们会粘在或“ float ”到屏幕顶部。在我的特定情况下,节标题是从其他 XIB 文件加载的。
是否可以根据节标题当前是否 float 来更改节标题?具体来说,我想添加一个小阴影,仅当它粘在 View 顶部时才出现在标题下方。
谢谢!
最佳答案
这是我创建的函数,用于更新每个标题是否有阴影。本例中的所有节标题都是 UIView 子类 ListHeader
。它们由 viewForHeaderInSection
函数保留并返回。
- (void) updateHeaderShadows {
int i=0;
int sectionHeight = 0;
int totalHeight = 0;
UIView * sectionHeader;
while (i<[self numberOfSectionsInTableView:self.tableView]) {
sectionHeight = [self.tableView rectForSection:i].size.height;
sectionHeader = [self tableView:self.tableView viewForHeaderInSection:i];
if ([sectionHeader respondsToSelector:@selector(shadow)]) {
if (sectionHeader.frame.origin.y == totalHeight || sectionHeader.frame.origin.y == totalHeight + sectionHeight - sectionHeader.frame.size.height) {
[((ListHeader *) sectionHeader).shadow setHidden:YES];
} else {
[((ListHeader *) sectionHeader).shadow setHidden:NO];
}
}
totalHeight += sectionHeight;
i++;
}
}
关于iphone - UITableView节头为 'Floating'时可以更改吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6861311/