1

I have a UITableView with 5 different sections. For one of those sections I have added a UIButton by doing:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

    if (section == 5) {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 64)];

    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];


    [button1 setTitle:@"Button" forState:UIControlStateNormal];


    button1.frame = CGRectMake(8, 8, 96, 44);



    [view addSubview:button1];


    return view;
    }
    return nil;
}

The problem that I am having is this: Since the Header for a section is by default aligned to the left, button is being aligned to the left, I have looked all around for a solution but can't seem to find one, your help/advice is appreciated!

4

2 に答える 2

2

ここでは、それ自体で整列するものは何もありません。ここで行うことは、セクション ヘッダーのキャンバス ビューを作成することです。これは正しいです。次に、原点(8, 8)がほぼ左上隅になるようにボタンを配置します。適切な原点座標を設定するだけで設定されます。

簡単にするために、ここで CGRect* 関数ファミリを確認する必要があります。

于 2013-07-17T04:39:02.190 に答える
2

配置要素はありません button1.frame = CGRectMake(8, 8, 96, 44);。ボタンのフレームを設定するポイントだけをビューの中央に設定すると、そのように表示されます

于 2013-07-17T04:43:59.560 に答える