导航栏下的UISementControll

时间:2018-10-08 11:14:52

标签: swift xcode navigation uinavigationbar uisearchcontroller

这是我的实现代码:

    @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
}

有一些奇怪的东西,然后进入此控制器:我试图设置色调颜色或更改大小,但没有帮助。问题的症结在哪里? enter image description here

1 个答案:

答案 0 :(得分:0)

尝试设置清晰的NavigationController颜色:

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