Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Sizing #2

Merged
merged 2 commits into from
Jun 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 171 additions & 2 deletions Sources/SetNeedsReadable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,54 @@ public extension CGFloat {

}

public enum Percentage: CGFloat {

case oneTenth = 0.10

case twoTenths = 0.20

case quarter = 0.25

case threeTenths = 0.30

case fourTenths = 0.40

case half = 0.5

case sixTenths = 0.60

case sevenTenths = 0.70

case threeQuarters = 0.75

case eightTenths = 0.80

case nineTenths = 0.90

case full = 1.0

case oneAndAQuarter = 1.25

case oneAndAHalf = 1.50

case oneAndThreeQuarters = 1.75

case double = 2.0

case triple = 3.0

case quadruple = 4.0

case quintuple = 5.0

}

// MARK: - UIView

public extension UIView {

// MARK: - Centering


/**
Aligns the caller so that it's horizontally centered with the view passed
inside the first argument.
Expand Down Expand Up @@ -282,7 +323,6 @@ public extension UIView {

// MARK: - Outside Alignment


/**
Aligns the caller so that it's right edge rests against the left edge of the
view passed in the first argument.
Expand Down Expand Up @@ -382,4 +422,133 @@ public extension UIView {
}
}


// MARK: - Sizing

/**
Sizes the height of the caller to match the height of the
view passed in the first argument.

- Parameter view: The view to match the caller's height to.
- Parameter percentage: The percentage of the height to match.
**/
final func sizeHeightTo(heightOf view: UIView, percentage: CGFloat = 1.0) {

frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: bounds.width, height: view.bounds.height * percentage)
}


/**
Sizes the height of the caller to match the height of the
view passed in the first argument.

- Parameter view: The view to match the caller's height to.
- Parameter percentage: The percentage of the height to match.
**/
final func sizeHeightTo(heightOf view: UIView, percentage: Percentage = .full) {

frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: bounds.width, height: view.bounds.height * percentage.rawValue)
}



/**
Sizes the height of the caller to match the width of the
view passed in the first argument.

- Parameter view: The view to match the caller's height to.
- Parameter percentage: The percentage of the height to match.
**/
final func sizeHeightTo(widthOf view: UIView, percentage: CGFloat = 1.0) {

frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: bounds.width, height: view.bounds.width * percentage)
}


/**
Sizes the height of the caller to match the width of the
view passed in the first argument.

- Parameter view: The view to match the caller's height to.
- Parameter percentage: The percentage of the height to match.
**/
final func sizeHeightTo(widthOf view: UIView, percentage: Percentage = .full) {

frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: bounds.width, height: view.bounds.width * percentage.rawValue)
}


/**
Sizes the height of the caller to a specific value

- Parameter value: The new value of the height.
**/
final func sizeHeightTo(_ value: CGFloat) {

frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: bounds.width, height: value)
}


/**
Sizes the width of the caller to match the width of the
view passed in the first argument.

- Parameter view: The view to match the caller's width to.
- Parameter percentage: The percentage of the width to match.
**/
final func sizeWidthTo(widthOf view: UIView, percentage: CGFloat = 1.0) {

frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: view.bounds.width * percentage, height: bounds.height)
}


/**
Sizes the width of the caller to match the width of the
view passed in the first argument.

- Parameter view: The view to match the caller's width to.
- Parameter percentage: The percentage of the width to match.
**/
final func sizeWidthTo(widthOf view: UIView, percentage: Percentage = .full) {

frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: view.bounds.width * percentage.rawValue, height: bounds.height)
}


/**
Sizes the width of the caller to match the height of the
view passed in the first argument.

- Parameter view: The view to match the caller's width to.
- Parameter percentage: The percentage of the height to match.
**/
final func sizeWidthTo(heightOf view: UIView, percentage: CGFloat = 1.0) {

frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: view.bounds.height * percentage, height: bounds.height)
}


/**
Sizes the width of the caller to match the height of the
view passed in the first argument.

- Parameter view: The view to match the caller's width to.
- Parameter percentage: The percentage of the width to match.
**/
final func sizeWidthTo(heightOf view: UIView, percentage: Percentage = .full) {

frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: view.bounds.height * percentage.rawValue, height: bounds.height)
}


/**
Sizes the width of the caller to a specific value

- Parameter value: The new value of the width.
**/
final func sizeWidthTo(_ value: CGFloat) {

frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: value, height: bounds.height)
}

}