Easily manipulate CGPoints, CGSizes and CGVectors using math operators
Welcome to CGOperators
, a small Swift framework that enables you to easily manipulate Core Graphics’ vector types (CGPoint
, CGSize
and CGVector
) using math operators. It can help you write compact, yet highly readable code when dealing with things like image sizes and frame-based layouts.
Add two vectors
let point = view.frame.origin + CGPoint(x: 10, y: 20)
let size = image.size + view.frame.size
let vector = physicsWorld.gravity + player.size
Subtract two vectors
let point = view.frame.origin - CGPoint(x: 10, y: 20)
let size = image.size - view.frame.size
let vector = physicsWorld.gravity - player.size
Multiply a vector with a constant
view.frame.size = image.size * 4
button.frame.origin = superview.bounds.size * 2
physicsWorld.gravity = player.position * 10
Divide a vector by a constant
view.frame.size = image.size / 4
button.frame.origin = superview.bounds.size / 2
physicsWorld.gravity = player.position / 10
Using CocoaPods
Add pod CGOperators
to your Podfile
Using Carthage
Add git "JohnSundell/CGOperators"
to your Cartfile
Using the Swift Package Manager
Add Package(url: "https://github.com/JohnSundell/CGOperators.git", majorVersion: 1)
to your Package.swift
file.
Using Marathon
Run marathon add https://github.com/JohnSundell/CGOperators.git
on the command line.
CGOperators
.CGOperators
and other open source projects.