我想創建我自己的自定義UIView分組UITableView
的標題。這是我到目前爲止玩的代碼:自定義UIView的tableView委託方法
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
Target *aTarget = [targetDictionary objectForKey:[NSNumber numberWithInteger:section]];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, self.TargetTableView.frame.size.width, 20)];
headerLabel.text = [NSString stringWithFormat:@"%@", aTarget.condition];
headerLabel.textColor = [UIColor whiteColor];
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.TargetTableView.frame.size.width, 200)];
headerView.backgroundColor = [UIColor orangeColor];
// [headerView addSubview:headerLabel];
return [headerView autorelease];
}
幾個問題。對於我的headerView,我希望高度爲40,但看起來很小。然後我將它改爲60,並且我看到它在我的UITableView
中根本沒有改變(我在彈出窗口中呈現這些數據,我認爲這不應該是重要的)。所以我做了200的高度,看看它是否會改變,我看到的橙色視圖很小。可能只有狀態欄那麼大。我們有我的UILabel
。我希望它能以我的UIView
爲中心。當我展示它時,它甚至不在我的UIView
中。這是我的第一排UITableView
的頂部。當我使用CGRectMake()
初始化它時,它是將它設置在父視圖的座標中還是將它移開?我試圖創建它,當我將它添加到我的headerView中時,我想定位它。
最後,如果我想添加一個簡單的背景漸變到我的tableView,我只是設置UITableView.backgroundColor = [UIColor clearColor]
,並將backgroundView設置爲漸變?因爲這似乎不工作?我只看到分組tableView的默認顏色。謝謝。
可能需要將其分解爲單獨的問題。首先,你是否實現了'tableView:heightForHeaderInSection:'? – jrturton 2012-01-30 22:04:35