Created
October 31, 2018 09:35
-
-
Save bawn/68e9c20caf785ba3ce20efd3d38a18a2 to your computer and use it in GitHub Desktop.
修复 iOS 12.1 上 UITabBar 里面的 items 偏移问题
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]}) | |
} | |
} | |
} |
In viewDidLoad
setValue(HQTabBar(), forKey: "tabBar")
请问下有没有oc版的
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, 感谢提供方案。
请问下如果不使用storyboard,用纯代码怎么可以替换原来的tab bar到我们自定义的tab bar?
用了override tab bar 结果layoutSubviews都不调用。
用setvalue(mTabBar, "tabBar")是没偏移问题,但是好多tab Bar原先的功能又没了