[英]How to correct the tableview section header frame according to the orientation / UITableView width
我有一個分組樣式的UITableView-我有一個自定義標題視圖:
+ (UIView *) viewForHeaderWithText: (NSString*) title
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
UIView *viewHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
UILabel *label = [[UILabel alloc] init];
label.backgroundColor = [UIColor clearColor];
label.frame = CGRectMake(10.0f, 0.0f, 300.0f, 20.0f);
label.font = [UIFont systemFontOfSize:12.0f];
label.textColor = [UIColor blackColor];
label.textAlignment = NSTextAlignmentLeft;
label.text = title;
if (!IS_OS_7_OR_LATER) {
label.textColor = [UIColor lightGrayColor];
}
[viewHeader addSubview:label];
return viewHeader;
}
}
因此,節標題寬度框架是固定的。
但是對於不同的方向和呈現UITableViewController的方式,更改了單元格寬度(iOS6)-如您在屏幕截圖中所見。 但是我需要使節標題和單元格的偏移量相等。
我現在有:
我需要的:
我試圖更改像元寬度-但無法解決此問題。有什么幫助嗎?
您需要在uitableView委托方法下面實現此功能:-
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.