14

I created a toolbar programmatically:

UIToolbar *boolbar = [UIToolbar new];
    boolbar.barStyle = UIBarStyleDefault;
    boolbar.tintColor = [UIColor orangeColor];
    [boolbar sizeToFit];

And then added a button to it:

UIBarButtonItem *cancelleftBarButton =[[UIBarButtonItem alloc]initWithTitle:@"OK" style:UIBarButtonItemStyleBordered target:self action:@selector(tapBackGround:)];

cancelleftBarButton.tintColor = [UIColor orangeColor];

NSArray *array = [NSArray arrayWithObjects:cancelleftBarButton, nil];
[boolbar setItems:array animated:YES];

However, this button appears only at the left side of the toolbar. Is it possible to put it on the right side of the toolbar ?

enter image description here

4

2 に答える 2

36

UIBarButtonItemツールバーの右側にを追加する方法は次のとおりです。

UIBarButtonItem *leftButton = [[[UIBarButtonItem alloc] initWithTitle:@"Item" style:UIBarButtonItemStyleBordered target:self action:@selector(btnItem1Pressed:)] autorelease];

UIBarButtonItem *flex = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil] autorelease];

UIBarButtonItem *rightButton = [[[UIBarButtonItem alloc] initWithTitle:@"Item" style:UIBarButtonItemStyleBordered target:self action:@selector(btnItem2Pressed:)] autorelease];

また

XIBから実行しようとしている場合は、。

「フレキシブルスペース」という識別子を持つアイテムを挿入します。

ここに画像の説明を入力してください

于 2012-10-13T06:59:33.997 に答える