Skip to content

Instantly share code, notes, and snippets.

@bawn
Created October 31, 2018 09:35
Show Gist options
  • Save bawn/68e9c20caf785ba3ce20efd3d38a18a2 to your computer and use it in GitHub Desktop.
Save bawn/68e9c20caf785ba3ce20efd3d38a18a2 to your computer and use it in GitHub Desktop.
修复 iOS 12.1 上 UITabBar 里面的 items 偏移问题
import UIKit
class HQTabBar: UITabBar {
var itemFrames = [CGRect]()
var tabBarItems = [UIView]()
override func layoutSubviews() {
super.layoutSubviews()
if itemFrames.isEmpty, let UITabBarButtonClass = NSClassFromString("UITabBarButton") as? NSObject.Type {
tabBarItems = subviews.filter({$0.isKind(of: UITabBarButtonClass)})
tabBarItems.forEach({itemFrames.append($0.frame)})
}
if !itemFrames.isEmpty, !tabBarItems.isEmpty, itemFrames.count == items?.count {
tabBarItems.enumerated().forEach({$0.element.frame = itemFrames[$0.offset]})
}
}
}
@xieweizhi
Copy link

In viewDidLoad

setValue(HQTabBar(), forKey: "tabBar")

@xuezhenchao
Copy link

请问下有没有oc版的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment