美文网首页
iOS13 tabBar bug

iOS13 tabBar bug

作者: MonkeyLu | 来源:发表于2020-02-28 15:45 被阅读0次

    * 在 iOS13 中,设置好的 tabBar 选中颜色 push 后 pop 回来(严格说是页面消失在出现:包括 modal 一个控制器),变成系统默认蓝色

    * 自定义控制器继承于 UIViewController

    * 应用中所有的视图都继承自该自定义控制器

    * 在该自定义控制器的 viewWillAppear 中,通过如下代码恢复 tabBar 选中颜色

    ```swift

    override func viewWillAppear(_ animated: Bool) {

        super.viewWillAppear(animated)

        if #available(iOS 13.0, *) {

            let appearance = UITabBarAppearance()

            // 设置未被选中的颜色

            appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.getColorFromRgba("7a7e82")]

            // 设置被选中时的颜色

            appearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.getColorFromRgba("f39800")]

            navigationController?.tabBarController?.tabBar.standardAppearance = appearance

        } else {

            // Fallback on earlier versions

        }

    }

    ```

    相关文章

      网友评论

          本文标题:iOS13 tabBar bug

          本文链接:https://www.haomeiwen.com/subject/llelhhtx.html