1
我使用以下代碼在TabBar項目之間添加分隔符視圖。它們在iPhone中可見,但在iPad中不可見。如何在TabBar項目之間插入分隔符UITapBarController
//Add seprators Line
if let items = self.tabBar.items {
//Get the height of the tab bar
let height = self.tabBar.bounds.height
//Calculate the size of the items
let numItems = CGFloat(items.count)
let itemSize = CGSize(
width: tabBar.frame.width/numItems,
height: tabBar.frame.height)
for (index, _) in items.enumerated() {
//We don't want a separator on the left of the first item.
if index > 0 {
//Xposition of the item
let xPosition = itemSize.width * CGFloat(index)
/* Create UI view at the Xposition,
with a width of 0.5 and height equal
to the tab bar height, and give the
view a background color
*/
let separator = UIView(frame: CGRect(
x: xPosition, y: 0, width: 0.5, height: height))
separator.backgroundColor = UIColor.blue
tabBar.insertSubview(separator, at: 1)
}
}
}