UIToolBar
4のカスタムを実装しましたUIbutton
。これらのボタンは画像付きのボタンです。私はこのコードでそれらを作成しました:
-(NSArray *)setButtonForToolBar
{
CGRect buttonFrame = {
.origin.x = 0,
.origin.y = 0,
.size.width = self.frame.size.width/4,
.size.height = self.frame.size.height,
};
NSLog(@"Frame width: %f and Origin x: %f ", buttonFrame.size.width, buttonFrame.origin.x );
// BOTON CHECK IN
UIButton *checkinButton = [[UIButton alloc]initWithFrame:buttonFrame] ;
[checkinButton addTarget:self action:@selector(checkInService:) forControlEvents:UIControlEventTouchUpInside];
[checkinButton setImage:[UIImage imageNamed:@"btn-checkin.png"] forState:UIControlStateNormal];
[checkinButton setImage:[UIImage imageNamed:@"btn-checkin-selected.png"] forState:UIControlStateHighlighted | UIControlStateSelected];
checkinButton.tag = 0;
UIBarButtonItem *checkInBarBtn = [[UIBarButtonItem alloc] initWithCustomView: checkinButton];
// BOTON PARA LA INFO
buttonFrame.origin.x = CGRectGetMaxX(buttonFrame);
NSLog(@"Frame width: %f and Origin x: %f ", buttonFrame.size.width, buttonFrame.origin.x );
UIButton *infoBtn = [[UIButton alloc]initWithFrame:buttonFrame];
[infoBtn addTarget:self action:@selector(checkInService:) forControlEvents:UIControlEventTouchUpInside];
[infoBtn setImage:[UIImage imageNamed:@"btn-info.png"] forState:UIControlStateNormal];
[infoBtn setImage:[UIImage imageNamed:@"btn-info-selected.png"] forState:UIControlStateHighlighted | UIControlStateSelected];
infoBtn.tag = 1;
UIBarButtonItem *infoBarBtn = [[UIBarButtonItem alloc] initWithCustomView: infoBtn];
// BOTON PARA VALORACIONES
buttonFrame.origin.x = CGRectGetMaxX(buttonFrame);
NSLog(@"Frame width: %f and Origin x: %f ", buttonFrame.size.width, buttonFrame.origin.x );
UIButton *voteBtn = [[UIButton alloc]initWithFrame:buttonFrame];
[voteBtn addTarget:self action:@selector(checkInService:) forControlEvents:UIControlEventTouchUpInside];
[voteBtn setImage:[UIImage imageNamed:@"btn-comment.png"] forState:UIControlStateNormal];
[voteBtn setImage:[UIImage imageNamed:@"btn-comment-selected.png"] forState:UIControlStateHighlighted];
voteBtn.tag = 2;
UIBarButtonItem *voteBarBtn = [[UIBarButtonItem alloc] initWithCustomView: voteBtn];
// BOTON PARA PLANES
buttonFrame.origin.x = CGRectGetMaxX(buttonFrame);
NSLog(@"Frame width: %f and Origin x: %f ", buttonFrame.size.width, buttonFrame.origin.x );
UIButton *planBtn = [[UIButton alloc]initWithFrame:buttonFrame];
[planBtn addTarget:self action:@selector(checkInService:) forControlEvents:UIControlEventTouchUpInside];
[planBtn setImage:[UIImage imageNamed:@"btn-fav.png"] forState:UIControlStateNormal];
[planBtn setImage:[UIImage imageNamed:@"btn-fav-selected.png"] forState:UIControlStateHighlighted | UIControlStateSelected];
planBtn.tag = 3;
UIBarButtonItem *planBarBtn = [[UIBarButtonItem alloc] initWithCustomView: planBtn];
NSArray *buttonItems = [NSArray arrayWithObjects:checkInBarBtn, infoBarBtn, voteBarBtn, planBarBtn, nil];
return buttonItems;
}
ToolBar
= (10,400,300,60) のフレームで作成されます。
出力を見てくださいNSlog
:
2013-11-21 17:43:18.557 Woowplanet[3316:70b] Frame width: 75.000000 and Origin x: 0.000000
2013-11-21 17:43:18.569 Woowplanet[3316:70b] Frame width: 75.000000 and Origin x: 75.000000
2013-11-21 17:43:18.570 Woowplanet[3316:70b] Frame width: 75.000000 and Origin x: 150.000000
2013-11-21 17:43:18.571 Woowplanet[3316:70b] Frame width: 75.000000 and Origin x: 225.000000
出力は、それらが正しい場所にあることを示しています.なぜそれらが右にほぼ10ポントあるのかわかりません..
問題は、ボタンが正しい場所にないことです。写真を見てください
ありがとうございました。