iPhone ツールバーを均等に配置する

ツールバーにボタンなどを単純に追加すると、左寄せになってしまう。





UIToolbar* toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 480-44, 320, 44)];
 UIBarButtonItem* prevButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(clickPrev)];
    UIBarButtonItem* nextButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward target:self action:@selector(clickNext)];
    UIBarButtonItem* space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    [toolBar setItems:[NSArray arrayWithObjects:space, prevButton, space, nextButton, space, nil]];



それを均等にする方法




間にUIBarButtonSystemItemFlexibleSpaceを入れるだけ。


UIToolbar* toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 480-44, 320, 44)];
    UIBarButtonItem* prevButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(clickPrev)];
    UIBarButtonItem* nextButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward target:self action:@selector(clickNext)];
    UIBarButtonItem* space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    [toolBar setItems:[NSArray arrayWithObjects:space, prevButton, space, nextButton, space, nil]];

0 件のコメント:

コメントを投稿

ReactNativeでAndroid対応する話

前提 ReactNativeでiOS版のアプリをリリースしていて、Android版をリリースする話 トラブルシューティング Build.VERSION_CODES.Q が存在しないエラー compileSdkVersionを29以上にすると解決 メモリー足りないエラー Execu...