如何在TabBar项目之间插入分隔符UITapBarController

我使用以下代码在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)

}

}

}

回答:

它工作。这是我用的:

self.tabBar.itemPositioning = UITabBarItemPositioning.fill 

以上是 如何在TabBar项目之间插入分隔符UITapBarController 的全部内容, 来源链接: utcz.com/qa/267154.html

回到顶部