UIToolbar
カスタム画像を使用して 5 つのボタンを作成しようとしています。私がこれを行っている方法は、タイプのボタンを作成し、次にこれらからUIButtonTypeCustom
作成UIBarButtonItems
し、これらをツールバーに追加することsetItems:animated:
です。ただし、これにより画像間にスペースが追加され、5 番目の画像がツールバーの右側から半分はみ出してしまいます。これらのスペースを取り除くにはどうすればよいですか? 考えられることはすべて試しました。
助けていただければ幸いです。
これについて私がどのように行っているかについてのコード例を次に示します。
UIButton *button;
UIBarButtonItem *barButton1,*barButton2;
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"image1.png"] forState:UIControlStateNormal];
button.bounds = CGRectMake(0,0,button.imageView.image.size.width, button.imageView.image.size.height);
[button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
barButton1 = [[UIBarButtonItem alloc] initWithCustomView:button];
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"bart_tb.png"] forState:UIControlStateNormal];
button.bounds = CGRectMake(0,0,button.imageView.image.size.width, button.imageView.image.size.height);
[button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
barButton2 = [[UIBarButtonItem alloc] initWithCustomView:button];
NSArray *items = [NSArray arrayWithObjects: barButton1, barButton2, nil];
[self.toolbar setItems:items animated:NO];