Skip to content

Instantly share code, notes, and snippets.

@cemolcay
Created October 16, 2017 13:27
Show Gist options
  • Save cemolcay/74859fac5dcdb3caf26013499c15563b to your computer and use it in GitHub Desktop.
Save cemolcay/74859fac5dcdb3caf26013499c15563b to your computer and use it in GitHub Desktop.
func convertValue(oldValue: CGFloat, oldMin: CGFloat, oldMax: CGFloat, newMin: CGFloat, newMax: CGFloat) -> CGFloat {
let oldRange = oldMax - oldMin
let newRange = newMax - newMin
return (((oldValue - oldMin) * newRange) / oldRange) + newMin
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment