А что тут думать та?
frame.width в кастомном view в layoutSubviews
Что это за набор слов? Зачем?
2570 = 630 + 440 + 1500
2570 - 100%
630 - x
x = (630 * 100) / 2570 ~ 24.5
2570 - 100%
440 - x
x = (440 * 100) / 2570 ~ 17.1
2570 - 100%
1500 - x
x = (1500 * 100) / 2570 ~ 58.3
class StackProgressView: UIView {
var proportion = 1.0
override var intrinsicContentSize: CGSize {
return CGSize(width: proportion, height: 1.0)
}
}
let stack = UIStackView(frame: CGRect(origin: .zero, size:CGSize(width: 500.0, height: 20.0)))
stack.distribution = .fillProportionally
stack.axis = .horizontal
stack.spacing = 5.0
let walk = StackProgressView(frame: .zero)
walk.backgroundColor = UIColor(red: 162.0 / 255.0, green: 221.0 / 255.0, blue: 239.0 / 255.0, alpha: 1.0)
walk.proportion = 24.5
walk.layer.allowsEdgeAntialiasing = true
walk.layer.cornerRadius = 5.0
walk.layer.maskedCorners = [.layerMinXMinYCorner, .layerMinXMaxYCorner]
let aerobic = StackProgressView(frame: .zero)
aerobic.backgroundColor = UIColor(red: 69.0 / 255.0, green: 187.0 / 255.0, blue: 223.0 / 255.0, alpha: 1.0)
aerobic.proportion = 17.1
let run = StackProgressView(frame: .zero)
run.backgroundColor = UIColor(red: 40.0 / 255.0, green: 112.0 / 255.0, blue: 133.0 / 255.0, alpha: 1.0)
run.proportion = 58.3
run.layer.allowsEdgeAntialiasing = true
run.layer.cornerRadius = 5.0
run.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMaxXMaxYCorner]
stack.addArrangedSubview(walk)
stack.addArrangedSubview(aerobic)
stack.addArrangedSubview(run)