兄弟们 雨过地皮湿呀
tabbar item title颜色
if #available(iOS 13, *) {
UITabBar.appearance().unselectedItemTintColor = UIColor.init(0xA6C0D4);
self.tabBar.tintColor = UIColor.init(0x6979F8);
} else {
viewCon.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor :UIColor.init(0x6979F8)], for: UIControl.State.selected)
viewCon.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor :UIColor.init(0xB5B8D0)], for: UIControl.State.normal)
}
关闭图片渲染
/// 根据图片名称 获取不被渲染的image
func imgGet(imgName:String) -> UIImage {
return (UIImage.init(named:imgName)?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal))!
}
隐藏tabbar的黑线
方法1 用view遮挡
let bgView = UIView.init(frame: self.view.bounds)
bgView.frame.origin.y = -1
bgView.backgroundColor = UIColor.white
self.tabBar.insertSubview(bgView, at: 0)
//方法2 透明img
if #available(iOS 13, *) {
let appearance = tabBar.standardAppearance.copy()
appearance.backgroundImage = self.getImageWithColor(color: .clear)
appearance.shadowImage = self.getImageWithColor(color: .clear)
tabBar.standardAppearance = appearance
} else {
//取掉tabbar的黑线
self.tabBar.backgroundImage = UIImage.init()
self.tabBar.shadowImage = UIImage.init()
}
/// 将颜色转换为图片
///
/// - Parameter color: UIColor
/// - Returns: UIImage
func getImageWithColor(color:UIColor)->UIImage {
let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
context!.setFillColor(color.cgColor)
context!.fill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}
修改tabbar的高度
- (void)viewDidLayoutSubviews {
CGRect tabFrame = self.tabBar.frame;
tabFrame.size.height = 73 + LL_TabbarSafeBottomMargin;
tabFrame.origin.y = self.view.frame.size.height - 73 - LL_TabbarSafeBottomMargin ;
self.tabBar.frame = tabFrame;
}