ボタンを作成し、このガイドを使用してこれをタブバーの上に配置しました。
selectedIndexが2の場合にのみ、このボタンを強調表示/選択したい。selectedIndexが0 1 3 4の場合、を通常の状態にしたくない。これは可能ですか?
次のことを試しましたが、ボタンがハイライト表示されますが、ボタンをクリックするとすぐにハイライトが消えて戻りません。
if (self.tabBarController.selectedIndex == 2) {
button.selected = YES;
button.highlighted = YES;
}else {
button.selected = NO;
button.highlighted = NO;
}
必要に応じて、タブバーにボタンをロードするコード:
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect buttonFrame = button.frame;
buttonFrame.size.height = 55;
buttonFrame.size.width = 64;
buttonFrame.origin.x = 128;
buttonFrame.origin.y = 424;
button.frame = buttonFrame;
[button setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"buttonhighlight.png"] forState:UIControlStateHighlighted];
[button setBackgroundImage:[UIImage imageNamed:@"buttonhighlight.png"] forState:UIControlStateSelected];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[_tabBarController.view addSubview:button];