I have a view with a subview that is designed to show a user what fraction of games they have won and lost, like so:
The width of the green view is calculated by taking the width of the superview, multiplying it by the fraction of games won (which in this case is .5), and changing the width constraint of the green view to the calculated value.
let percent = Float(won)/Float(self.partiesPlayed) //percent of games won, should be .5 let width = CGFloat(percent) * self.winLoseView.bounds.size.width //multiply width of superview by percent self.greenWidthConstraint.constant = CGFloat(width) //change constraint's constant UIView.animateWithDuration(2, animations: { // animate change self.view.layoutIfNeeded() }) 
The problem is that the width does not appear to be exactly correct, for instance in this example it doesn't appear to be exactly half of the superview.