Some useful extensions for Swift: UIView UIColor
width: CGFloat
let width = view.width
height: CGFloat
let height = view.width
size: CGSize
let size = view.size
origin: CGPoint
let origin = view.origin
x: CGFloat
let viewX = view.x
y: CGFloat
let viewY = view.y
centerX: CGFloat
let centerX = view.centerX
centerY: CGFloat
let centerY = view.centerY
left: CGFloat
let left = view.left
right: CGFloat
let right = view.right
top: CGFloat
let top = view.top
bottom: CGFloat
let bottom = view.bottom
round(corners: UIRectCorner, radius: CGFloat)
view.round(corners: [.bottomLeft, .bottomRight], radius: 7.0)
parentViewController
let parentViewController = view.parentViewController
let color = UIColor(hexadecimalString: "#444444ff")!
Where final 'ff' stands for the alpha value.
let image = UIImage(color: 'UIColor', size: 'CGSize')
let image = UIImage(view: 'UIView')
let image = UIImage(color: '[CGColor]', size: 'CGSize')
let image = UIImage().alpha('CGFloat')
let image = UIImage().alphaGray('CGFloat')
let ratio = image.aspectRatio(between: 'CGSize', and: 'CGSize')
Scales an image to fit within a bounds with a size governed by the passed size. Also keeps the aspect ratio.
image.scaled(to: 'CGSize', scalingMode: .aspectFill)
image.scale(to: 'CGSize', scalingMode: .aspectFill)