我通過tableView的委託方法提供自定義節標題。它在平面模式下工作正常,但我無法弄清楚分組風格的正確邊距。當tableView模式分組時,確定自定義節標題框
有誰知道如何使與細胞的tableView對齊節頭?
我通過tableView的委託方法提供自定義節標題。它在平面模式下工作正常,但我無法弄清楚分組風格的正確邊距。當tableView模式分組時,確定自定義節標題框
有誰知道如何使與細胞的tableView對齊節頭?
沒有在每一個味道測試,但一個很好的起點。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
將tableView.style參數傳遞給您自己的提供標題的方法。 創建一個視圖像
CGRect(0,0,CGRectGetWidth(tableView.frame), CGRectGetHeight(tableView.frame)
一個框架,但添加一個子視圖與框架
CGRectInset(frame, 30,0)
如果你有一個分組的tableView風格。將autoresizingMask設置爲靈活的寬度並且可以工作。
稍微修改一下,我必須爲SectionHeaderView的創建方法提供一個附加參數,因爲對於presentationStyle FullScreen和Formsheet,頁邊距不同。
CGFloat margin = 0;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
margin = style == UITableViewStyleGrouped ? modalStyle == UIModalPresentationFormSheet ? 28 : 38 : 0;
}
else {
margin = style == UITableViewStyleGrouped ? 5 : 0;
}
UIView *view = [[UIView alloc] initWithFrame:CGRectInset(frame, margin, 0)];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self addSubview:view];
您可以創建自定義標籤並相應地調整其框架。 例如。
- (UIView *)tableView:(UITableView *)aTableView viewForHeaderInSection:(NSInteger)section
{
UIView *view=[[UIView alloc] initWithFrame:aTableView.tableHeaderView.frame];
UILabel *label=[[UILabel alloc] initWithFrame: CGRectMake(//set frame of the label as you want)];
[label setFont:[UIFont fontWithName: size:]];
[label setTextColor:[UIColor blackColor]];
[label setShadowOffset:CGSizeMake(0.0f, 1.0f)];
[label setShadowColor:[UIColor redColor];
label.backgroundColor=[UIColor clearColor];
if(section==0)
{
[label setText://set your section0 title];
}
else if(section ==1)
{
[label setText://set your section1 title];
}
[view addSubview:label];
[label release];
return [view autorelease];
}
Hope this helps :)
我剛剛找到了我的答案。不管怎麼說,還是要謝謝你。 –