2016-11-28 1022 views
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) 
      } 
     } 
    } 

回答

1

它工作。这是我用的:

self.tabBar.itemPositioning = UITabBarItemPositioning.fill 
相关问题