在UITabViewController的所有欄中只顯示一個視圖(UIButton)。
應該怎麼實現呢?
比如info按鈕在欄中一直顯示,不用將它添加到xib或重寫代碼。
執行一個Tab Bar Controller類,在viewDidLoad方法中,循環遍歷全部Tab Bar View Controllers添加按鈕。
- (void)viewDidLoad
{
[super viewDidLoad];
for(UIViewController *viewController in [self viewControllers]){
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
CGRect buttonRect = infoButton.frame;
// This will place the button 20px away from the top right corner
buttonRect.origin.x = self.view.frame.size.width - buttonRect.size.width - 20;
buttonRect.origin.y = 20;
[infoButton setFrame:buttonRect];
[infoButton addTarget:self action:@selector(showInfo:) forControlEvents:UIControlEventTouchUpInside];
[viewController.view addSubview:infoButton];
}
}