iphone - 在所有选项卡中显示单个 View (UITabBarController)

标签 iphone ios objective-c user-interface

如何让单个 View (UIButton) 在 UITabViewController 的所有选项卡中可见?

例如,我需要在所有选项卡中保持单个“信息”按钮可见,而不是将其添加到所有选项卡的 XIB 中,并且不重写所有选项卡中的重复代码。

最佳答案

实现一个选项卡栏 Controller 类,并在 viewDidLoad 方法中循环遍历所有选项卡栏 View Controller 并以编程方式添加按钮。

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

关于iphone - 在所有选项卡中显示单个 View (UITabBarController),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17748899/

相关文章:

ios - 使用地址簿作为数据源

ios - SKPhysicsBody 不适用于 SKShapeNode

javascript - 通过从字符串评估 JavaScript 来取消字符串

iOS8 方向 : supportedInterfaceOrientations called but no orientation change

iphone - 从 TableView 中删除多个单元格

ios - 在 ITC 审查期间观看 OS3、UIRequiredDeviceCapabilities 问题

ios - 选项卡栏图标除第一个图标外均已加载。在模拟器中工作。 Objective-c

ios - 对属性和 ivars 感到困惑

ios - Activity View Controller在新行中显示URL

iphone - 滚动花式框不适用于 iPhone 或 iPad