我正在尝试创建一个垂直进度条。但是问题是我的代码在 IOS11或更高版本上有效,但是在 IOS9 上却无效。
在 IOS11或更高版本上,它看起来像: enter image description here
但是在 IOS9 上,它看起来像:enter image description here
我的代码:
>>> help(int)
[ Squeezed text (241 lines) ] # <== tkinter button
>>>
layoutSubview()
let progressBar: UIProgressView = {
let prgressView = UIProgressView()
prgressView.progress = 0.7
prgressView.progressTintColor = UIColor(red: 1.0, green: 0.21, blue: 0.33, alpha: 1)
prgressView.trackTintColor = UIColor.blue
prgressView.layer.cornerRadius = 6.5
prgressView.clipsToBounds = true
prgressView.transform = CGAffineTransform(rotationAngle: .pi / -2)
prgressView.translatesAutoresizingMaskIntoConstraints = false
return prgressView
}()
viewDidLoad()
override func layoutSubviews() {
super.layoutSubviews()
let width = progressBar.bounds.width
let height = progressBar.bounds.height
progressBar.bounds.size.width = height
progressBar.bounds.size.height = width
}
我正在按照本教程创建垂直的progressView:https://www.youtube.com/watch?v=ifekgTtb0rQ&t=1070s
答案 0 :(得分:0)
通过对发布的代码进行两项更改,我能够使您的代码在iOS 9和iOS 12下正常工作:
layoutSubviews
。您已设置约束。也不要尝试直接修改视图的框架。简而言之,删除layoutSubviews
并将您的约束条件修正为:
progressBar.widthAnchor.constraint(equalToConstant: 250).isActive = true
progressBar.heightAnchor.constraint(equalToConstant: 22.5).isActive = true