我有一个继承自UITabBarController
的子类,我想在选中的UITabBarItem
图标下方添加一个小的白色矩形图标。我使用了一个UIView
,并将TabBarItem
作为其子视图,并将该视图作为其子视图添加到其中。我在viewWillAppear
方法中这样做,它显示出来了,但当我选择另一个选项卡时,它不会出现在那个选项卡下面。
以下是我的代码:
let view = orderedTabBarItemViews()[selectedIndex]
bottomIcon.frame = CGRect(x: 0, y: 42, width: 10, height: 3)
bottomIcon.center = CGPoint(x: view.bounds.size.width / 2, y: view.bounds.size.height / 2)
bottomIcon.backgroundColor = UIColor.white
bottomIcon.layer.cornerRadius = 2
view.addSubview(bottomIcon)
orderedTabBarItemViews()
函数将TabBarItem
作为UIView
数组返回。下面是我想要实现的效果的图片。