我是一个很新的编程设计,我被一些东西卡住了。
所以我有下面的代码,在这里我创建了一个新的视图,实际上我想把它放在我的图标和标签栏背景之间。

      let tabBarItem1 = myTabBar.items![0] as UITabBarItem
    let tabBarItem2 = myTabBar.items![1] as UITabBarItem
    let tabBarItem3 = myTabBar.items![2] as UITabBarItem
    let tabBarItem4 = myTabBar.items![3] as UITabBarItem

    tabBarItem1.selectedImage = UIImage(named: "image1")!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    tabBarItem2.selectedImage = UIImage(named: "image2")!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    tabBarItem3.selectedImage = UIImage(named: "image3")!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    tabBarItem4.selectedImage = UIImage(named: "image4")!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)


    let viewSelected = UIView(frame: CGRectMake(30, 5, 40, 40))
    viewSelected.backgroundColor = UIColor.whiteColor()
    viewSelected.layer.cornerRadius = 4
    //layer.borderColor = UIColor.whiteColor().CGColor
    //layer.borderWidth = 2
    viewSelected.layer.masksToBounds = true

    // add subview to tabBarController?.tabBar
    myTabBar.addSubview(viewSelected)

目前,当我添加子视图时,得到以下结果
ios - 在标签栏和标签栏项目之间添加 subview-LMLPHP
问题是我想在图标(现在在视图后面)和背景之间有这个视图。谢谢!

最佳答案

将添加子视图的行替换为:

myTabBar.insertSubview(viewSelected, belowSubview: myTabBar.subviews.first!)

它应该做这个工作!

关于ios - 在标签栏和标签栏项目之间添加 subview ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36151680/

10-13 03:51