8

我想以编程方式快速制作 UIProgressBar 吗?

这段代码有什么问题?

 override func viewDidLoad() {
    super.viewDidLoad()
        let progressView = UIProgressView(progressViewStyle: .Bar)
        progressView.center = self.view.center
        progressView.frame = CGRectMake(0,0,50,20)
        progressView.translatesAutoresizingMaskIntoConstraints = false
        progressView.setProgress(0.5, animated: false)
        self.view.addSubview(progressView)
 }
4

2 回答 2

10
let progressView = UIProgressView(progressViewStyle: .Bar)
progressView.center = view.center
progressView.setProgress(0.5, animated: true)
progressView.trackTintColor = UIColor.lightGrayColor()
progressView.tintColor = UIColor.blueColor()
view.addSubview(progressView)

您需要执行此类型代码,并且您不需要设置 frame 。

于 2016-06-08T07:00:37.207 回答
0

你需要:

  1. 添加你的progressView的子视图
  2. 设置约束,因为您使 translateAutoresizingMaskIntoConstraints = false
于 2020-10-23T08:54:31.293 回答