我有一個UITableView
的static
單元格,使用storyboards
創建兩個部分。我使用下面的代碼來改變部分headers
的外觀。UIView中的UILabel for viewForHeaderInSection不滾動表。
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(20, 1, 320, 20);
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor lightGrayColor];
label.shadowColor = [UIColor grayColor];
label.shadowOffset = CGSizeMake(-1.0, 1.0);
label.font = [UIFont boldSystemFontOfSize:10];
label.text = sectionTitle;
UIView *view = [[UIView alloc] init];
[view addSubview:label];
return view;
}
它看起來就是我想要的,但滾動tableView
時,在第一頭的label
不與UIView
滾動。它停留在屏幕中間。至於第二個標題中的label
,它的行爲就像它應該的那樣。
我想你可以直接返回UILabel而不是將它包裝在UIView和As按照https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UITableViewDelegate/tableView:viewForHeaderInSection:您還必須實現tableView:heightForHeaderInSection: – Piyuesh
它的工作返回'UILabel',但我得到同樣的問題。謝謝。 – Jorge
iOS有粘滯部分標題。因此,當您滾動時,它們在表格視圖的頂部保持可見狀態,並且只有當用戶滾動到其部分的結尾時才滾動。如果您轉到Apple的任何應用程序(例如音樂),則會在歌曲列表中看到此行爲,並在節標題中顯示字母。這有助於保持用戶的上下文。這個問題可能對你有用:http://stackoverflow.com/questions/664781/change-default-scrolling-behavior-of-uitableview-section-header –