ログイン



Flexible Bar Button ItemとFixed Bar Button Itemの生成

金曜日, 11月 18th, 2011 by

Flexible Bar Button ItemとFixed Bar Button Itemは、以下のように生成します。これらのUIBarButtonItemを使うことでUIToolbar内のボタンの表示位置を調整できます。

UIBarButtonItem *fixed = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

以下のように使います。

UIToolbar * toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f,0.0f, 320.0f, 50.0f)];
toolbar.items = [NSArray arrayWithObjects:
 [[UIBarButtonItem alloc] initWithTitle:@"Button1" style:UIBarButtonItemStyleBordered target:nil action:nil],
 [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
 [[UIBarButtonItem alloc] initWithTitle:@"Button2" style:UIBarButtonItemStyleBordered target:nil action:nil],
 [[UIBarButtonItem alloc] initWithTitle:@"Button3" style:UIBarButtonItemStyleBordered target:nil action:nil],
 nil];

スクリーンショット

button1とbutton2の間に”Flexible Bar Button Item”が入っています。

Comments

comments