Skip to content

Instantly share code, notes, and snippets.

@ukitaka
Created February 10, 2017 06:54
Show Gist options
  • Save ukitaka/31052b46c44dd08257dc010a4fd1beeb to your computer and use it in GitHub Desktop.
Save ukitaka/31052b46c44dd08257dc010a4fd1beeb to your computer and use it in GitHub Desktop.
percentage postfix operator
postfix operator %
public postfix func %(int: Int) -> CGFloat {
return CGFloat(int) / 100.0
}
public postfix func %(int: Int8) -> CGFloat {
return CGFloat(int) / 100.0
}
public postfix func %(int: Int16) -> CGFloat {
return CGFloat(int) / 100.0
}
public postfix func %(int: Int32) -> CGFloat {
return CGFloat(int) / 100.0
}
public postfix func %(int: Int64) -> CGFloat {
return CGFloat(int) / 100.0
}
public postfix func %(int: UInt) -> CGFloat {
return CGFloat(int) / 100.0
}
public postfix func %(int: UInt8) -> CGFloat {
return CGFloat(int) / 100.0
}
public postfix func %(int: UInt16) -> CGFloat {
return CGFloat(int) / 100.0
}
public postfix func %(int: UInt32) -> CGFloat {
return CGFloat(int) / 100.0
}
public postfix func %(int: UInt64) -> CGFloat {
return CGFloat(int) / 100.0
}
100% // 1.0
0% // 0.0
80% // 0.8
UIColor(white: 0%, alpha: 80%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment