我有一個UITabBarController
子類,我想在選定的UITabBarItem
圖標下添加一個白色的小長方形圖標。我使用了UIView
,我將TabBarItem
作爲子視圖並將視圖添加爲子視圖。我在viewWillAppear
中這樣做,它顯示,但是當我選擇另一個選項卡時,它不會出現在該選項卡欄項下。 這裏是我的代碼:如何在Swift中的選定UITabBarItem圖標下面添加小圖標
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
S作爲的UIView
秒的陣列。 這裏是我想要達到