0

tableView のデリゲート メソッドを介してカスタム セクション ヘッダーを提供します。平面モードでは問題なく動作しますが、グループ化されたスタイルで正しいマージンを把握できません。

スクリーンショット

セクションヘッダーをtableViewセルに揃える方法を知っている人はいますか?

4

2 に答える 2

0

カスタム ラベルを作成し、それに応じてフレームを調整できます。たとえば。

- (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 :)
于 2012-12-06T07:07:17.590 に答える
0

すべてのフレーバーでテストされているわけではありませんが、良い出発点です。ヘッダーを提供する独自のメソッドに
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
tableView.style パラメータを渡します。フレームのようなビューを作成し ますが、グループ化された tableView スタイルがある場合は
CGRect(0,0,CGRectGetWidth(tableView.frame), CGRectGetHeight(tableView.frame)
フレーム付きのサブビューを追加します。
CGRectInset(frame, 30,0)
autoresizingMask を柔軟な幅に設定すると機能します。

presentationStyle FullScreen と Formsheet では余白が異なるため、SectionHeaderView の作成メソッドに追加のパラメーターを指定する必要があるように少し変更しました。

        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];
于 2012-12-06T07:37:31.730 に答える