这是我的实现代码:
@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
}
答案 0 :(得分:0)
尝试设置清晰的NavigationController颜色:
navigationController?.view.backgroundColor = isBlack ? .black : .clear