Int
public extension Int
-
Scale a value proportionally to the current screen width. Useful for making designed sizes look proportionally similar on all devices.
For instance, let’s say a certain button was meant to take up 30px of an iPhone 6s screen, but you’d like the width to scale proportionally to an iPhone SE:
>>> 30.scaledToDeviceWidth(baseWidth: 375) 25.6
Date
February 17, 2016Declaration
Swift
func scaledToDeviceWidth(_ baseWidth: CGFloat) -> CGFloat
Parameters
baseWidth
The base width for the provided value.
Return Value
A
CGFloat
that represents the proportionally sized value. -
Convert an Int value representing RGBA color components into red, green, blue, and alpha CGFloat representations.
This is useful for converting something like a HEX representation of a color to RGBA. For instance:
var r: CGFloat! var g: CGFloat! var b: CGFloat! var a: CGFloat! 0xFF000000.toRGBA(&r, &g, &b, &a) // r = 1, g = 0, b = 0, a = 0
Date
May 24, 2017Declaration
Swift
func toRGBA(_ r: inout CGFloat!, _ g: inout CGFloat!, _ b: inout CGFloat!, _ a: inout CGFloat!)
Parameters
r
The variable to write the red color value to.
g
The variable to write the green color value to.
b
The variable to write the blue color value to.
a
The variable to write the alpha value to.