在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];
}
}