私は3つのUIBarButtonItemsをプログラムでUIToolbarに設定したいのですが、これはインラインアプリケーションと同じです。つまり、左端の追加ボタンその後 -Emoボタンと右端の送信ボタン
これまでのところ、私はこれを行ってきました
UIImage *imageSend = [UIImage imageNamed:@"btnSend.png"];
imageSend = [imageSend stretchableImageWithLeftCapWidth:floorf(imageSend.size.width/2) topCapHeight:floorf(imageSend.size.height/2)];
UIButton *btnSend = [UIButton buttonWithType:UIButtonTypeCustom];
btnSend.titleLabel.font = [UIFont boldSystemFontOfSize:15.0f];
btnSend.titleLabel.shadowOffset = CGSizeMake(0, -1);
btnSend.titleEdgeInsets = UIEdgeInsetsMake(0, 2, 0, 2);
btnSend.contentMode = UIViewContentModeScaleToFill;
[btnSend setBackgroundImage:imageSend forState:UIControlStateNormal];
[btnSend setTitle:@"Send" forState:UIControlStateNormal];
[btnSend addTarget:self action:@selector(inputButtonPressed) forControlEvents:UIControlEventTouchDown];
[btnSend sizeToFit];
self.barBtnSend = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
self.barBtnSend.customView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
[self.barBtnSend setCustomView:btnSend];
self.barBtnSend.width=235;
/* Disable button initially */
self.barBtnSend.enabled = NO;
UIImage *imgAttach = [UIImage imageNamed:@"iconAttach.png"];
self.btnAttach = [UIButton buttonWithType:UIButtonTypeCustom];
[self.btnAttach setBackgroundImage:imgAttach forState:UIControlStateNormal];
[self.btnAttach setFrame:CGRectMake(3, 3, 28, 29)];
[self.btnAttach addTarget:self action:@selector(inputImageButtonPressed) forControlEvents:UIControlEventTouchDown];
self.barBtnAdd = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[self.barBtnAdd setCustomView:self.btnAttach];
self.barBtnAdd.customView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
self.barBtnAdd.width=10;
UIImage *imgEmoji = [UIImage imageNamed:@"iconSmiley.png"];
imgEmoji = [imgEmoji stretchableImageWithLeftCapWidth:floorf(imgEmoji.size.width/2) topCapHeight:floorf(imgAttach.size.height/2)];
//
self.btnCustomEmoji = [UIButton buttonWithType:UIButtonTypeCustom];
[self.btnCustomEmoji setBackgroundImage:imgEmoji forState:UIControlStateNormal];
[self.btnCustomEmoji setFrame:CGRectMake(34, 3, 28, 29)];
[self.btnCustomEmoji addTarget:self action:@selector(showCustomKeyboard) forControlEvents:UIControlEventTouchDown];
[self.btnCustomEmoji sizeToFit];
[self addSubview:self.btnCustomEmoji];
self.barBtnCustomEmoji = [[UIBarButtonItem alloc] initWithCustomView:self.btnCustomEmoji];
self.barBtnCustomEmoji.customView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
NSArray *items = [NSArray arrayWithObjects:self.barBtnSend,self.barBtnAdd,nil];
[self setItems:items animated:NO];
しかし、私は望ましい結果を得ていません。私のボタンは重なり合っており、左側に来ており、デフォルトの幅も取っています。