非标准UITabBarItem动作

时间:2015-04-22 16:01:51

标签: swift uitabbarcontroller uitabbaritem

我有一个视图为enter image description here

的UITabBarController

所以在每个TabBar上我都有ViewController。但是在我的中心UITabBarItem上,我需要调用像modal UIViewController这样的东西。它应该是这样的 enter image description here

我的UITabBarController类看起来像

class PlanetTabBarController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tabBar.tintColor = kTintColor

        var items = self.tabBar.items as! [UITabBarItem]
        let centredTabBar:UITabBarItem = items[2]
        self.tabBar.layer.borderWidth = 0.50

        centredTabBar.image = ktabCentredBarImage
        self.tabBar.layer.borderColor = UIColor.clearColor().CGColor
        self.tabBar.layer.borderWidth = 0

        self.tabBar.shadowImage = UIImage()
        // self.tabBar.backgroundImage = ktabBarImage
        self.tabBar.backgroundImage?.imageWithAlignmentRectInsets

        print( UIDevice.currentDevice().modelName)
        if( UIDevice.currentDevice().modelName != "iPhone 6" && UIDevice.currentDevice().modelName != "iPhone 6 Plus") {
           self.tabBar.backgroundImage = ktabBarImage 
        }
        if( UIDevice.currentDevice().modelName == "iPad 2" ) {
            self.tabBar.backgroundImage = ktabBarImage
        }

        if let font = UIFont(name: "Avenir-Black", size: 10) {
            let appearance = UITabBarItem.appearance()
            let attributes = [NSFontAttributeName:font]
            appearance.setTitleTextAttributes(attributes, forState: UIControlState.Normal)
        }
    }
}

我真的不知道如何覆盖UIViewController的标准调用并调用这样的模态=)请给我建议我需要搜索的地方

1 个答案:

答案 0 :(得分:0)

您可以将UIButton放置在与UITabBarItem相同的区域中并触发操作,也可以在selectedSegmentIndex更改(“值已更改”中)时触发操作)创建中心UITabBarUITabBarItem。设计选择是你的。第一步是了解您正在使用的对象。在底部的标准UITabBar顶部添加一个按钮(居中对齐)可能会更容易,因此您不需要处理自定义UITabBarController来处理标签栏上方的非均匀图像。

或者只是在那里创建自己的TabBar。非常简单地设置几个没有静态高度的UIButton或UIViews,例如允许该中心对象的UITabBarController

UITabBarController

UIViewController

Presenting a ViewController