9

UITableViewのフッターで2つのUIButtonを使用しています(両方とも単一のUIViewのサブビュー)。連絡先の編集時など、一部のiPhone画面の下部にある赤い[削除]ボタンのように見えるようにボタンをスキンしたかったので、UITableViewCellを使用していません。

サイズが正しく、正しく機能します。ただし、デバイスの向きの変更(横向き、縦向きなど)に応じてテーブルのサイズが変更され、ボタンは元の幅のままになります。自動サイズ変更マスクを使用してみましたが、何も機能しませんでした。

それへのトリック、またはより良い方法はありますか?

4

4 に答える 4

14

自動サイズ変更マスクで動作するはずです。以前に実行しましたが、ビューの幅を正しく設定し、正しいサイズ変更マスクを追加することが重要です。

それがどのように機能するかを示すいくつかのサンプルコード。これにより、回転する部分のサイズを変更する2つのボタンが作成されます。

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 50)];

    view.backgroundColor = [UIColor redColor];

    UIButton *buttonA = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    buttonA.frame = CGRectMake(20, 5, 125, 40);
    [buttonA setTitle:@"ButtonA" forState:UIControlStateNormal];
    buttonA.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

    [view addSubview:buttonA];

    UIButton *buttonB = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    buttonB.frame = CGRectMake(175, 5, 125, 40);
    [buttonB setTitle:@"ButtonB" forState:UIControlStateNormal];
    buttonB.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

    [view addSubview:buttonB];

    return [view autorelease];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 50;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return YES;
}
于 2011-05-24T20:06:16.320 に答える
0

ボタンに2つのフレームを使用してください。1つは横向きモード用、もう1つは縦向きモード用です。これでうまくいきます。したがって、向きが変わると、横向きまたは縦向きを確認し、フレームを割り当てます。ここでモードを確認すると、インターフェースの向きに回転します。

于 2011-05-18T10:14:15.177 に答える
0

私が思いついた最善の方法は、独自のセクションで1つのボタンと1つのセルを使用することです。そうすれば、それぞれが適切にサイズ変更されます。

于 2011-05-24T15:34:56.437 に答える
0

ボタンが1つしかないことを除けば、私はあなたと非常によく似たことをします。返すuiviewは、tableView自体と同じ幅である必要があります。

CGFloat footerWidth = mainTableView.frame.size.width;
CGRect frameTableFooter = CGRectMake(0.0, 0.0, footerWidth, 60.0);  
viewForTableFooter.frame = frameTableFooter;
// buttons addition
mainTableView.tableFooterView = viewForTableFooter;
于 2011-05-24T19:51:30.183 に答える