Autolayout and View Animation Helper for Swift 3.0. Mimimum requirements: Swift 3 and IOS 9 Supported: IOS and Apple TV
// Required
view.animate(.Shake, curve: .EaseInOutBack)
// With optionals
view.animate(.Shake, curve: .EaseInOutBack, duration: 0.8, delay: 0, force: 1, damping: 0.7,velocity: 1, fromRotation: 0, fromScale: 1.5, fromX: 0, fromY: 0)
let box = UIView(autoLayout:true)
view.addSubview(box)
box.backgroundColor = UIColor.redColor()
box.width(100)
box.height(100)
box.center(to: view)
view.layoutIfNeeded()
100 pixel view pinned to the center of another view
view.width(100).height(100).center(to: view)
view.horizontalCompressionPriority(UILayoutPriorityDefaultHigh)
view.horizontalHuggingPriority(UILayoutPriorityDefaultLow)
You can have access to the NSLayoutConstraints by using pin() or applyAttribute.
// Pinning to an item
let widthConstraint = view.pin(.Width, to: view, attribute: .Height, constant: 0, multiplier: 0.5, relation: .LessThanOrEqual)
// Applying an attribute
let widthConstraint = view.applyAttribute(.Width, constant: 100, multiplier: 0.5, relation: .Equal)
If a view is already in place with frames, prepForAutoLayout() will remove it from view, enable Auto Layout and place back in view.
view.prepForAutoLayout()
If a view uses auto layout but you need to animate it using frames, prepForAnimation() will remove from view, disable auto layout and place back in view.
view.prepForAnimation()
Instantiates a new UIView with Auto Layout
convenience init(autoLayout: Bool = true)
Returns the frame's origin
origin() -> CGPoint
Pins the frame's top and left sides using Auto Layout or frames
origin(constant: CGPoint) -> UIView
Pins left and top sides to another view using Auto Layout
origin(to to:AnyObject, constant: CGPoint = CGPoint(x: 0, y: 0), multiplier:CGFloat = 1) -> UIView
Returns the min x point
left() -> CGFloat
Pins the left side using Auto Layout or frames
left(constant: CGFloat) -> UIView
Pins left side to another view using Auto Layout
left(to to:AnyObject, attribute: NSLayoutAttribute = .Left, constant: CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Returns the leading side value
leading() -> CGFloat
Pins the leading side using Auto Layout or frames
leading(constant: CGFloat) -> UIView
Pins the leading side to another view using Auto Layout
leading(to to:AnyObject, attribute: NSLayoutAttribute = .Leading, constant: CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Returns the max x point
right() -> CGFloat
Pins the right side using Auto Layout or frames
right(constant: CGFloat) -> UIView
Pins the right side to another view using Auto Layout
right(to to:AnyObject, attribute: NSLayoutAttribute = .Right, constant: CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Returns the trailing side value
trailing() -> CGFloat
Pins the trailing side using Auto Layout or frames
trailing(constant: CGFloat) -> UIView
Pins the trailing side to another view using Auto Layout
trailing(to to:AnyObject, attribute: NSLayoutAttribute = .Trailing, constant: CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Returns the top side value
top() -> CGFloat
Pins the top side using Auto Layout or frames
top(constant: CGFloat) -> UIView
Pins the trailing side to another view using Auto Layout
top(to to:AnyObject, attribute: NSLayoutAttribute = .Top, constant: CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Returns the bottom side value
bottom() -> CGFloat
Pins the bottom side using Auto Layout or frames
bottom(constant: CGFloat) -> UIView
Pins the bottom side to another view using Auto Layout
bottom(to to:AnyObject, attribute: NSLayoutAttribute = .Bottom, constant: CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Pins the center to it's superview using Auto Layout or frames
center(constant: CGPoint = CGPoint(x: 0, y: 0)) -> UIView
Pins the center point to another view using Auto Layout
center(to to:AnyObject, constant:CGSize = CGSize(width: 0, height: 0), multiplier:CGFloat = 1) -> UIView
Returns the center X
centerX() -> CGFloat
Pins the center X using Auto Layout or frames
centerX(constant: CGFloat = 0) -> UIView
Pins the center X to another view using Auto Layout
centerX(to to:AnyObject, attribute: NSLayoutAttribute = .CenterX, constant: CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Returns the center Y
centerY() -> CGFloat
Pins the center Y using Auto Layout or frames
centerY(constant: CGFloat = 0) -> UIView
Pins the center Y to another view using Auto Layout
centerY(to to:AnyObject, attribute: NSLayoutAttribute = .CenterY, constant: CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Returns the Compression Resistance Priority for Horizontal Axis using Auto Layout
horizontalCompressionPriority() -> UILayoutPriority
Sets the Compression Resistance Priority for Horizontal Axis using Auto Layout
horizontalCompressionPriority(priority: UILayoutPriority) -> UIView
Returns the Compression Resistance Priority for Vertical Axis using Auto Layout
verticalCompressionPriority() -> UILayoutPriority
Sets the Compression Resistance Priority for Vertical Axis using Auto Layout
verticalCompressionPriority(priority: UILayoutPriority) -> UIView
Returns the Content Hugging Priority for Horizontal Axis using Auto Layout
func horizontalHuggingPriority() -> UILayoutPriority
Sets the Content Hugging Priority for Horizontal Axis using Auto Layout
horizontalHuggingPriority(priority: UILayoutPriority) -> UIView
Returns the Content Hugging Priority for Vertical Axis using Auto Layout
verticalHuggingPriority() -> UILayoutPriority
Sets the Content Hugging Priority for Vertical Axis using Auto Layout
verticalHuggingPriority(priority: UILayoutPriority) -> UIView
Returns the frame size
size() -> CGSize
Sets the frame size using Auto Layout or frames
size(constant: CGSize) -> UIView
Pins the size to another view using Auto Layout
size(to to:AnyObject, constant: CGSize = CGSize(width: 0, height: 0), multiplier:CGFloat = 1) -> UIView
Returns the frame width
width() -> CGFloat
Sets the frame width using Auto Layout or frames
width(constant: CGFloat) -> UIView
Pins the width to another view using Auto Layout
width(to to:AnyObject, attribute: NSLayoutAttribute = .Width, constant: CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Returns the frame height
height() -> CGFloat
Sets the frame height using Auto Layout or frames
eight(constant: CGFloat) -> UIView
Pins the height to another view using Auto Layout
height(to to:AnyObject, attribute: NSLayoutAttribute = .Height, constant: CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Returns the minimum size using Auto Layout
minSize() -> CGSize?
Sets the minimum size using Auto Layout
minSize(constant:CGSize) -> UIView
Pins the minimum size to another view using Auto Layout
minSize(to to:AnyObject, constant:CGSize = CGSize(width: 0, height: 0), multiplier:CGFloat = 1)
Returns the minimum width using Auto Layout
minWidth() -> CGFloat?
Sets the minimum width using Auto Layout
minWidth(constant:CGFloat) -> UIView
Pins the minimum width to another view using Auto Layout
minWidth(to to:AnyObject, attribute: NSLayoutAttribute = .Width, constant:CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Returns the minimum height using Auto Layout
minHeight() -> CGFloat?
Sets the minimum height using Auto Layout
minHeight(constant:CGFloat) -> UIView
Pins the minimum height to another view using Auto Layout
minHeight(to to:AnyObject, attribute: NSLayoutAttribute = .Height, constant:CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Returns the maximun size using Auto Layout
maxSize() -> CGSize?
Sets the maximun size using Auto Layout
maxSize(constant:CGSize) -> UIView
Pins the maximun size to another view using Auto Layout
maxSize(to to:AnyObject, constant:CGSize = CGSize(width: 0, height: 0), multiplier:CGFloat = 1) -> UIView
Returns the maximun width using Auto Layout
maxWidth() -> CGFloat?
Sets the maximun width using Auto Layout
maxWidth(constant:CGFloat) -> UIView
Pins the maximun width to another view using Auto Layout
maxWidth(to to:AnyObject, attribute: NSLayoutAttribute = .Width, constant:CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Returns the maximun height using Auto Layout
maxHeight() -> CGFloat?
Sets the maximun height using Auto Layout
maxHeight(constant:CGFloat) -> UIView
Pins the maximun height to another view using Auto Layout
maxHeight(to to:AnyObject, attribute: NSLayoutAttribute = .Height, constant:CGFloat = 0, multiplier:CGFloat = 1) -> UIView
Returns the length of the smallest side
smallestSideLength() -> CGFloat
Returns the length of the largest side
largestSideLength() -> CGFloat
Prepares the view for a frame based animation by removing the view, enabling translatesAutoresizingMaskIntoConstraints and re-adding the view to it's superview
prepForAnimation()
Prepares the view for Auto Layout by removing the view, disabling translatesAutoresizingMaskIntoConstraints and re-adding the view to it's superview
prepForAutoLayout()
Pins an attribute to another view
pin(pinAttribute:NSLayoutAttribute, to:AnyObject? = nil, attribute:NSLayoutAttribute, constant:CGFloat = 0, multiplier:CGFloat = 1, relation:NSLayoutRelation = .Equal) -> NSLayoutConstraint?
Applies an attribute to the view
applyAttribute(attribute:NSLayoutAttribute, constant:CGFloat = 0, multiplier: CGFloat = 1, relation:NSLayoutRelation = .Equal) -> NSLayoutConstraint
Removes all attached constraints recursevely
removeAttachedConstraintsRecursevely() -> UIView
Removes a constraint recursevely
removeConstraintRecursevely(constraint:NSLayoutConstraint) -> UIView
Returns true if layout direction is left to right
layoutDirectionIsLeftToRight() -> Bool
The layer border color
var borderColor: UIColor
The layer border width
var borderWidth: CGFloat
Sets layer border with a dash pattern
borderWithDashPattern(lineDashPattern: [Int], borderWidth: CGFloat, borderColor: UIColor, cornerRadius: CGFloat?) -> UIView
The layer corner radius
var cornerRadius: CGFloat
Creates a circle by rounding the corners to half the size of the width, sets border color and width
roundCornersToCircle(borderColor: UIColor?, borderWidth: CGFloat?) -> UIView
Creates a circle by rounding the corners to hald the size of the width
roundCorners(cornerRadius: CGFloat, borderColor: UIColor?, borderWidth: CGFloat?) -> UIView
The shadow color of the layer
var shadowColor: UIColor
The shadow offset of the layer
var shadowOffset:CGSize
The shadow opacity of the layer
var shadowOpacity:Float
The shadow radius of the layer
var shadowRadius:CGFloat
Sets shadow of the layer including the color, offset, radius, opacity and mask.
shadow(color: UIColor = UIColor.blackColor(), offset: CGSize = CGSize(width: 0, height: 0), radius: CGFloat = 6, opacity: Float = 1, isMasked: Bool = false) -> UIView
Sets a gradient color layer
setGradient(colors: [UIColor], isHorizontal:Bool = false) -> UIView
Animates colors of a gradient layer
animateGradientToColors(colors: [UIColor], duration: CFTimeInterval = 3) -> UIView
Sets a gradient layer mask
setGradientMask(alphas:[CGFloat], isHorizontal:Bool = false) -> UIView
Returns true if layout direction is left to right
layoutDirectionIsLeftToRight() -> Bool
Returns true if horizontal size class is compact
horizontalSizeClassIsCompact() -> Bool
Returns true if vertical size class is compact
verticalSizeClassIsCompact() -> Bool