设置navigationController?.navigationBar.prefersLargeTitles = true会禁用默认样式...如何将其设置为Apple样式?

时间:2019-10-11 21:19:59

标签: uinavigationbar ios13 xcode11 swift5

设置preferredsLargeTitle = true看起来与错误版本完全不同-我猜这是设计使然。但是,如果我想让它看起来完全一样,即下面的灰色细线还是半透明的怎么办?

状态栏也是透明的-我是否必须为其设置背景色,以便滚动内容不会发光?但这不是那个线程和当前的最大问题。 ;)

所有设置都不起作用,我只是不知道为什么...顺便说一句。没有分镜脚本版本!

ViewController

class ViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white

        let tabBar = UITabBar.appearance()
        tabBar.barStyle = .default
        tabBar.isTranslucent = true

        let vcOne = UINavigationController(rootViewController: ViewOneController())
        vcOne.tabBarItem.image = UIImage(systemName: "house.fill")
        vcOne.tabBarItem.title = "One"

        let vcTwo = UINavigationController(rootViewController: ViewTwoController())
        vcTwo.tabBarItem.image = UIImage(systemName: "list.dash")
        vcTwo.tabBarItem.title = "Two"

        let vcThree = UINavigationController(rootViewController: ViewThreeController())
        vcThree.tabBarItem.image = UIImage(systemName: "trash.fill")
        vcThree.tabBarItem.title = "Two"
        viewControllers = [vcOne, vcTwo, vcThree]
    }

}

ViewOneConroller

class ViewOneController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationItem.title = "Controller One"

    }

}

第一个Controller的结果以及我希望在大标题版本上具有的有关背景,阴影等的“设计”或“样式”:

Result of the first ViewController

ViewTwoController

class ViewTwoController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationItem.title = "Controller Two"
        self.navigationController?.navigationBar.prefersLargeTitles = true
    }

}

这是第二个视图控制器没有任何设置,但大标题设置为“ true”的结果:

Result of the second ViewController

ViewThreeController

class ViewThreeController: UIViewController {

    let img: UIImageView = {
        let imageView           = UIImageView()
        imageView.image         = UIImage(named: "image")
        return imageView
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white

        view.addSubview(img)
        img.translatesAutoresizingMaskIntoConstraints = false
        img.contentMode   = .scaleAspectFit
        NSLayoutConstraint.activate([
            img.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            img.topAnchor.constraint(equalTo: view.topAnchor, constant: -50),
            img.widthAnchor.constraint(equalToConstant: 500)
        ])

        navigationItem.title = "Controller Three"

        self.navigationController?.navigationBar.prefersLargeTitles = true
        self.navigationController?.navigationBar.backgroundColor    = .white
        self.navigationController?.navigationBar.shadowImage        = UIImage(contentsOfFile: "shadow")
        self.navigationController?.navigationBar.isTranslucent      = true

        // setting it via BarAppearance has no effect neither?!
        UINavigationBarAppearance().shadowColor = .black



    }

}

第三个带有设置但没有设置的设置会产生任何影响,就像您在下面的图像中看到的那样。

enter image description here

0 个答案:

没有答案
相关问题