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

Commit

Permalink
Introduce sizing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Rehat Kathuria authored and Rehat Kathuria committed Jun 26, 2017
1 parent 2573e60 commit b6d2f32
Showing 1 changed file with 129 additions and 2 deletions.
131 changes: 129 additions & 2 deletions Sources/SetNeedsReadable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ 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 @@ -324,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 @@ -424,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)
}

}

0 comments on commit b6d2f32

Please sign in to comment.