请告诉我如何在导航栏下面添加一个ProgressView?
我尝试使用此帖子中的解决方案: adding progress bar under navigation bar ,但是该代码是用ObjectiveC语言编写的…… 我试图将其翻译为Swift。这是我在NavigationController子类中添加的代码
但是当我编译我的应用程序时,我没有在导航栏下看到进度视图。
我的错误在哪里?
import UIKit
class CustomNavigationController: UINavigationController {
@IBOutlet var Secondprogress: UIProgressView!
override func viewDidLoad() {
super.viewDidLoad()
NSLayoutConstraint.deactivateConstraints(self.view.constraints())
Secondprogress?.setTranslatesAutoresizingMaskIntoConstraints(false)
var navBar = self.navigationController?.navigationBar
Secondprogress.tag = 1
self.view.addSubview(Secondprogress)
var Constraint = NSLayoutConstraint(item: self.Secondprogress,
attribute:NSLayoutAttribute.Bottom,
relatedBy:NSLayoutRelation.Equal,
toItem:navBar,
attribute:NSLayoutAttribute.Bottom,
multiplier:1.0,
constant:-0.5);
self.view.addConstraint(Constraint);
Constraint = NSLayoutConstraint(item: self.Secondprogress,
attribute:NSLayoutAttribute.Left,
relatedBy:NSLayoutRelation.Equal,
toItem:navBar,
attribute:NSLayoutAttribute.Left,
multiplier:1.0,
constant:0);
self.view.addConstraint(Constraint);
Constraint = NSLayoutConstraint(item: self.Secondprogress,
attribute:NSLayoutAttribute.Right,
relatedBy:NSLayoutRelation.Equal,
toItem:navBar,
attribute:NSLayoutAttribute.Right,
multiplier:1.0,
constant:0);
self.view.addConstraint(Constraint);
Secondprogress.setTranslatesAutoresizingMaskIntoConstraints(false)
Secondprogress.hidden = false
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
但是当我编译我的应用程序时,我没有在导航栏下看到进度视图。
我的错误在哪里?