UITabBarController问题解决记录

开屏非主界面tabbarItem隐藏,点击后显示

在空白对应位置点击隐藏的tabbaritem,点击后正常显示

问题图片

e9201f84b3a74987b1bea4868a2b881c.png

问题原因

在每个ViewController里设置了tabBarItem和title,使得加载时无法及时获取,导致开屏后不显示,直到点击后才显示

问题代码

class FirstViewController: UIViewController {
    lazy var Label:UILabel = {
        let label = UILabel(frame: CGRect(x: 40, y: 150, width: 240, height: 44))
        label.text = "第一页"
        return label
    }()
    func setupView(){
        self.view.addSubview(Label)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        self.title = "识别"
        self.tabBarItem.image = UIImage(systemName: "arrow.3.trianglepath")
        setupView()
    }
}

解决方案

在SceneDelegate或者UITabBarController里面设置tabBarItem和title

运行结果

885bcdb555f044459a5d941331b56e86.png

tabbar呈半透明状,受界面背景色影响

tabbar随背景颜色变化而变化

问题图片

8919c93b79874dc1af61d90d5fb41e3d.png

解决方案

在SceneDelegate里面加入代码

        let defaultTabBarAppearance = UITabBarAppearance()
        defaultTabBarAppearance.backgroundColor = UIColor.white // 设置为你想要的固定颜色
        UITabBar.appearance().standardAppearance = defaultTabBarAppearance
        if #available(iOS 15.0, *) {
            UITabBar.appearance().scrollEdgeAppearance = defaultTabBarAppearance
        }

eg:发现更好的解决办法(结合运用更佳),删除上面代码tabbar会变成黑色背景:

        UITabBar.appearance().isTranslucent = false //避免受默认的半透明色影响,关闭
        UITabBar.appearance().barTintColor = UIColor.brown//设置背景颜色
        UITabBar.appearance().tintColor = UIColor.green//设置选中的背景颜色
        UITabBar.appearance().clipsToBounds = true //去掉上面的分割线

运行结果

ae07a8bb4bd545df881798f08be2f42a.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黑-麦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值