两个UITabbar iOS具有不同的UITabBar.Apperance

时间:2017-10-26 05:11:15

标签: ios swift uitabbar

我为不同的UITabBar设置UITabBar时遇到了一些困难。我们在同一屏幕上有2个TabBar,但TabBar的大小不同。

我需要在TabBar的不同位置设置此红线。

如何针对不同的UITabBar使用单独的TabBars外观?

来自AppDelegate.swift

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        UITabBar.appearance().selectionIndicatorImage = getImageWithColorPosition(color: UIColor(red:0.94, green:0.33, blue:0.21, alpha:1.0),                                                                                  size: CGSize(width:(self.window?.frame.size.width)!/4,height: 49), lineSize: CGSize(width:(self.window?.frame.size.width)!/4, height:2))
            return true     
}
    
func getImageWithColorPosition(color: UIColor, size: CGSize, lineSize: CGSize) -> UIImage {
      let rect = CGRect(x:0, y: 0, width: size.width, height: size.height)
      let rectLine = CGRect(x:0, y:size.height-lineSize.height,width: lineSize.width,height: lineSize.height)
      UIGraphicsBeginImageContextWithOptions(size, false, 0)
      UIColor.clear.setFill()
      UIRectFill(rect)
      color.setFill()
      UIRectFill(rectLine)
      let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
        UIGraphicsEndImageContext()
      return image
}

0 个答案:

没有答案