我在制作编程设计方面很陌生,而且我坚持不懈。 所以我有以下代码,我在其中创建一个新视图,我实际上想要放置在我的图标和标签栏的背景之间。
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)
目前,当我添加子视图时,我得到以下结果
问题是我希望将此视图置于图标(现在位于视图后面)和背景之间。谢谢!
答案 0 :(得分:0)
替换addSubview所在的行:
myTabBar.insertSubview(viewSelected, belowSubview: myTabBar.subviews.first!)
它应该做的工作!