简体   繁体   中英

Progress Bar goes beyond the frame

I create progress bar in my app using this code:

let progressBar = UIProgressView(progressViewStyle: .default)
progressBar.setProgress(1.0, animated: true)
self.addSubview(progressBar)

progressBar.trackTintColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.2)
progressBar.tintColor = .white

let frame = CGRect(x: percentLabel.intrinsicContentSize.width + 30.0, y: 117, width: 254, height: 3)
progressBar.frame = frame

And as you can see here: 屏幕截图2 屏幕截图1 If the progress is 1.0, progress bar goes beyond the frame. Any ideas how to fix that??

the percentLabel is pushing it to the right.

To fix this, you could constrain the progress bar to always start at the position that it has in the second photo. Add a leading constraint from the progress bar to its superview. And also give it a smaller width.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM