有什麼辦法可以將UITableView節頭視圖的寬度設置爲小於UITableView的整個寬度?現在,我設置tableView:viewForHeaderInSection:返回的視圖的寬度,標題視圖被拉伸到UITableView的寬度。如何設置UITableView標題視圖的寬度?
這裏是我的代碼:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *label = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 50, 50)];
label.backgroundColor = [UIColor yellowColor];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
return label;
}
感謝兩位響應者。我點擊Bala的答案,因爲他的方法解決了我的問題。但嚴格來說,返回的headerView仍然在tableview中變得越來越緊張,如果將其背景顏色更改爲紅色,則會變得明顯。我仍然很好奇爲什麼發生這種情況,但至少我現在可以對我的應用程序進行最後的修改。 – 2012-03-17 16:33:43