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

Commit

Permalink
Merge branch 'release/2.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Ermolenko committed Dec 25, 2017
2 parents 6d55b3a + 6d72969 commit 0e607c2
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Framezilla.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "Framezilla"
spec.version = "2.4.1"
spec.version = "2.5.0"
spec.summary = "Comfortable syntax for working with frames."

spec.homepage = "https://github.com/Otbivnoe/Framezilla"
Expand Down
10 changes: 0 additions & 10 deletions Framezilla.xcworkspace/contents.xcworkspacedata

This file was deleted.

2 changes: 1 addition & 1 deletion Sources/Array+Stack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum StackAxis: Int {
case vertical
}

public extension Array where Element: UIView {
public extension Collection where Iterator.Element: UIView, Self.Index == Int, Self.IndexDistance == Int {

/// Arranges views in the order of list along a vertical or horizontal axis, with spacing property.
///
Expand Down
56 changes: 38 additions & 18 deletions Sources/Maker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public final class Maker {

unowned let view: UIView

var handlers: [(priority: HandlerPriority, handler: HandlerType)] = []
var handlers = ContiguousArray<(priority: HandlerPriority, handler: HandlerType)>()
var newRect: CGRect

private var widthParameter: ValueParameter?
Expand Down Expand Up @@ -391,7 +391,25 @@ public final class Maker {
setHighPriorityValue(view.bounds.height, for: .height)
return self
}


/// Calculates the size that best fits the specified size.
///
/// ```
/// maker.sizeThatFits(size: CGSize(width: cell.frame.width, height: cell.frame.height)
/// ```
/// - parameter size: The size for best-fitting.
///
/// - returns: `Maker` instance for chaining relations.

@discardableResult public func sizeThatFits(size: CGSize) -> Maker {
let fitSize = view.sizeThatFits(size)
let width = min(size.width, fitSize.width)
let height = min(size.height, fitSize.height)
setHighPriorityValue(width, for: .width)
setHighPriorityValue(height, for: .height)
return self
}

/// Resizes and moves the receiver view so it just encloses its subviews only for height.
///
/// - returns: `Maker` instance for chaining relations.
Expand All @@ -401,7 +419,17 @@ public final class Maker {
setHighPriorityValue(view.bounds.height, for: .height)
return self
}


/// Calculates the height that best fits the specified size.
///
/// - returns: `Maker` instance for chaining relations.

@discardableResult public func heightThatFits(height: Number) -> Maker {
view.sizeToFit()
setHighPriorityValue(min(view.bounds.height, height.value), for: .height)
return self
}

/// Resizes and moves the receiver view so it just encloses its subviews only for width.
///
/// - returns: `Maker` instance for chaining relations.
Expand All @@ -411,25 +439,17 @@ public final class Maker {
setHighPriorityValue(view.bounds.width, for: .width)
return self
}

/// Calculates the size that best fits the specified size.
///
/// ```
/// maker.sizeThatFits(size: CGSize(width: cell.frame.width, height: cell.frame.height)
/// ```
/// - parameter size: The size for best-fitting.

/// Calculates the width that best fits the specified size.
///
/// - returns: `Maker` instance for chaining relations.

@discardableResult public func sizeThatFits(size: CGSize) -> Maker {
let fitSize = view.sizeThatFits(size)
let width = min(size.width, fitSize.width)
let height = min(size.height, fitSize.height)
setHighPriorityValue(width, for: .width)
setHighPriorityValue(height, for: .height)

@discardableResult public func widthThatFits(width: Number) -> Maker {
view.sizeToFit()
setHighPriorityValue(min(view.bounds.width, width.value), for: .width)
return self
}

// MARK: Middle priority

/// Creates margin relation for superview.
Expand Down
2 changes: 1 addition & 1 deletion Sources/UIView+Installer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public extension UIView {
}
}

public extension Array where Element: UIView {
public extension Sequence where Iterator.Element: UIView {

/// Configures frames of the views for special state.
///
Expand Down
76 changes: 76 additions & 0 deletions Tests/MakerWidthHeightTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,80 @@ class MakerWidthHeightTests: BaseTest {
}
XCTAssertEqual(testingView.frame, CGRect(x: 125, y: 187.5, width: 250, height: 125))
}

/* width / height to fit */

func testWidthToFit() {

let label = UILabel()
label.text = "HelloHelloHelloHello"

label.configureFrame { maker in
maker.widthToFit()
}
XCTAssertTrue(label.bounds.width > 0)
XCTAssertEqual(label.bounds.height, 0)
}

func testHeightToFit() {

let label = UILabel()
label.text = "HelloHelloHelloHello"

label.configureFrame { maker in
maker.heightToFit()
}
XCTAssertTrue(label.bounds.height > 0)
XCTAssertEqual(label.bounds.width, 0)
}

/* width / height that fits */

func testThat_widthThatFits_correctlyConfiguresRelativeLowMaxWidth() {

let label = UILabel()
label.text = "HelloHelloHelloHello"

label.configureFrame { maker in
maker.widthThatFits(width: 30)
}
XCTAssertEqual(label.bounds.width, 30)
XCTAssertEqual(label.bounds.height, 0)
}

func testThat_widthThatFits_correctlyConfiguresRelativeHighMaxWidth() {

let label = UILabel()
label.text = "HelloHelloHelloHello"

label.configureFrame { maker in
maker.widthThatFits(width: 300)
}
XCTAssertTrue(label.bounds.width != 300)
XCTAssertEqual(label.bounds.height, 0)
}

func testThat_heightThatFits_correctlyConfiguresRelativeLowMaxHeight() {

let label = UILabel()
label.text = "HelloHelloHelloHello"

label.configureFrame { maker in
maker.heightThatFits(height: 5)
}
XCTAssertEqual(label.bounds.height, 5)
XCTAssertEqual(label.bounds.width, 0)
}

func testThat_heightThatFits_correctlyConfiguresRelativeHighMaxHeight() {

let label = UILabel()
label.text = "HelloHelloHelloHello"

label.configureFrame { maker in
maker.heightThatFits(height: 300)
}
XCTAssertTrue(label.bounds.height != 300)
XCTAssertEqual(label.bounds.width, 0)
}
}

0 comments on commit 0e607c2

Please sign in to comment.