Skip to content

raulferrerdev/SwifXtensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwifXtensions

Some useful extensions for Swift: UIView UIColor

UIView

Get view dimensions

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 view corners

round(corners: UIRectCorner, radius: CGFloat)

view.round(corners: [.bottomLeft, .bottomRight], radius: 7.0)

Get parent view controller

parentViewController

let parentViewController = view.parentViewController

UIColor

Get UIColor from a hexadecimal string

let color = UIColor(hexadecimalString: "#444444ff")!

Where final 'ff' stands for the alpha value.

UIImage

Returns image with color

let image = UIImage(color: 'UIColor', size: 'CGSize')

Returns image from UIView

let image = UIImage(view: 'UIView')

Returns gradien color image

let image = UIImage(color: '[CGColor]', size: 'CGSize')

Returns image with alpha applied

let image = UIImage().alpha('CGFloat')

Returns image with alpha gray applied

let image = UIImage().alphaGray('CGFloat')

Calculates the aspect ratio between two sizes

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)

Scales image

image.scale(to: 'CGSize', scalingMode: .aspectFill)

About

Some extension for use in Xcode swift projects.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages