答案 0 :(得分:0)
以AppDelegate
didFinishLaunching
方法放置代码:-
let tabBarController = self.window!.rootViewController as! UITabBarController
let tabBar = tabBarController.tabBar
DispatchQueue.main.async {
tabBar.selectionIndicatorImage = UIImage().createSelectionIndicatorFill(fillColor:.red, lineColor:.blue,size: CGSize(width:tabBar.frame.width/CGFloat(tabBar.items!.count), height:tabBar.frame.height), lineWidth: 1.0)
tabBar.unselectedItemTintColor = customColor
}
并扩展UIImage
extension UIImage {
func createSelectionIndicatorFill(fillColor: UIColor,lineColor:UIColor,size: CGSize, lineWidth: CGFloat) -> UIImage {
UIGraphicsBeginImageContextWithOptions(size, false, 0)
fillColor.setFill()
UIRectFill(CGRect(x:0, y:0, width:size.width, height:size.height - lineWidth))
lineColor.setFill()
UIRectFill(CGRect(x:0, y:size.height - lineWidth, width:size.width, height:lineWidth))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}
答案 1 :(得分:0)
您可以通过创建自定义标签栏并添加该标签的每个方面视图控制器以通过以下步骤将其添加为子vc来实现。
使用视图创建自定义视图(将按钮和分隔符添加为 子视图)。您可以使用UIBezierPath或使用二进制图像来实现上角的曲线,并管理按钮和分隔符的行为,例如颜色。
在视图中添加第一个标签的VC确实已加载
self.add(asChildViewController: firstViewController)
在像这样的每个按钮上点击时添加/删除(显示/隐藏)子视图控制器
//MARK: - Add Child View Controller
private func add(asChildViewController viewController: UIViewController) {
// Add Child View Controller
addChildViewController(viewController)
// Add Child View as Subview
view.addSubview(viewController.view)
// Configure Child View
viewController.view.frame = view.bounds
viewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
// Notify Child View Controller
viewController.didMove(toParentViewController: self)
}
//MARK: - Remove Child View Controller
private func remove(asChildViewController viewController: UIViewController) {
// Notify Child View Controller
viewController.willMove(toParentViewController: nil)
// Remove Child View From Superview
viewController.view.removeFromSuperview()
// Notify Child View Controller
viewController.removeFromParentViewController()
}