Hãy nói cho tôi biết cách thêm một ProgressView dưới thanh điều hướng? Tôi cố gắng sử dụng giải pháp trong bài đăng này: adding progress bar under navigation bar, nhưng có mã được viết trên ngôn ngữ ObjectiveC ... Tôi cố gắng dịch sang Swift. Đây là mã, mà tôi thêm vào trong NavigationController lớp con tôiThêm thanh tiến trình trong thanh điều hướng nhanh chóng?
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.
}
}
Nhưng khi tôi biên dịch ứng dụng của tôi, tôi không thấy ProgressView dưới Navigation Bar.
Lỗi của tôi ở đâu?
Bạn nên chấp nhận câu trả lời để cho người dùng khác biết rằng câu hỏi của bạn đã được trả lời - mặc dù đó là câu hỏi của bạn. –
Tất nhiên! Nhưng stackoverflow nói với tôi rằng tôi có thể chấp nhận câu trả lời của tôi trong 12 giờ :) – Dmitry