배경보기로 UIView
를 사용합니다. 그런 다음 다른보기를 진행률 표시 줄과 같이 하위보기로 추가하십시오. 클래스로 그 구현 Let`s :
class ProgressView: UIView {
var progress: CGFloat = 0
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 = Colors.fontColor
super.init(frame: frame)
addSubview(filledView)
}
required init(coder aDecoder: NSCoder) { // <-- You need to implement this
fatalError()
}
func setProgess(var progress: CGFloat) {
progress = min(max(progress, 0), 1) // Between 0 and 1
self.progress = progress
filledView.frame.size.width = self.frame.width * progress
}
}
지금 당신은 또한 당신이 원하는 경우 비율을 보여주기 위해 UILabel
를 추가 할 수 있습니다.
왜 'UIProgressView'위에 'UILabel'을 표시하지 않으시겠습니까? – rmaddy