导航栏下的UISementControll

导航栏下的UISementControll

这是我的实现代码:

    @IBOutlet var toolBar: UIToolbar!
@IBOutlet var segmentControl: UISegmentedControl!

override func viewDidLoad() {
    super.viewDidLoad()

    self.title =  "Media"
    self.toolBar.delegate = self

    setupSegmentControl()
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
    navigationController?.navigationBar.shadowImage = UIImage()
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)

    navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
    navigationController?.navigationBar.shadowImage =  nil
}

fileprivate func setupSegmentControl() {
    let items = ["Photo", "Video", "Document"]
    self.segmentControl.removeAllSegments()
    for item in items {
        self.segmentControl.insertSegment(withTitle: item, at: items.index(of: item)!, animated: false)
    }

    self.segmentControl.selectedSegmentIndex = 0
}

func position(for bar: UIBarPositioning) -> UIBarPosition {
    return UIBarPosition.topAttached
}


有一些奇怪的东西,然后进入此控制器:我试图设置色调颜色或更改大小,但没有帮助。问题的症结在哪里?
swift - 导航栏下的UISementControll-LMLPHP

最佳答案

尝试设置清晰的NavigationController颜色:

navigationController?.view.backgroundColor = isBlack ? .black : .clear

关于swift - 导航栏下的UISementControll,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52701067/

10-09 23:05