I have a progressView (UIView) inside a UIView, and it over flows the bounds (using autolayout).
I have even tried sizeToFit()
and clipToBounds()
. Neither have solved the problem. When I println the width of the frame, it is the original value in Storyboard, which is too big when rendered on the device.
class ProgressView: UIView {
var progress: CGFloat! = 0.75
var filledView: UIView!
override init(frame: CGRect) {
filledView = UIView(frame: CGRect(x: frame.origin.x, y: frame.origin.y, width: 0, height: frame.height))
filledView.backgroundColor = UIColor.redColor()
super.init(frame: frame)
addSubview(filledView)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
filledView = UIView(frame: CGRect(x: frame.origin.x, y: frame.origin.y, width: 0, height: frame.height))
filledView.backgroundColor = UIColor.redColor()
addSubview(filledView)
}
func setProgress(var progress: CGFloat) {
progress = min(max(progress, 0), 1) // Between 0 and 1
self.progress = progress
println(self.frame.width)
filledView.frame.size.width = self.frame.width * progress
filledView.clipsToBounds = true
}
}
You just need to set the progress with:
self.progress = progress
It should animate by itself. No need to change any frames in there.
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.