Skip to content

Commit

Permalink
Merge branch 'release/2.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Ermolenko committed Feb 9, 2018
2 parents 52c9f5a + aff991e commit 2a2c43b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 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.8.0"
spec.version = "2.9.0"
spec.summary = "Comfortable syntax for working with frames."

spec.homepage = "https://github.com/Otbivnoe/Framezilla"
Expand Down
36 changes: 35 additions & 1 deletion Sources/Maker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

import Foundation

public enum Size {
case width
case height
}

enum HandlerPriority: Int {
case high
case middle
Expand Down Expand Up @@ -696,7 +701,36 @@ public final class Maker {
}

// MARK: Low priority


/// Set up the corner radius value.
///
/// - returns: `Maker` instance for chaining relations.

@discardableResult public func cornerRadius(_ cornerRadius: Number) -> Maker {
let handler = { [unowned self] in
self.view.layer.cornerRadius = cornerRadius.value
}
handlers.append((.low, handler))
return self
}

/// Set up the corner radius value as either a half-width or half-height.
///
/// - returns: `Maker` instance for chaining relations.

@discardableResult public func cornerRadius(byHalf type: Size) -> Maker {
let handler = { [unowned self] in
if case Size.width = type {
self.view.layer.cornerRadius = self.newRect.width / 2
}
else {
self.view.layer.cornerRadius = self.newRect.height / 2
}
}
handlers.append((.low, handler))
return self
}

/// Creates center relation to superview.
///
/// Use this method when you want to center view by both axis relativity superview.
Expand Down
31 changes: 31 additions & 0 deletions Tests/MakerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,35 @@ class MakerTests: BaseTest {
XCTAssertEqual(label.bounds.width, 30)
XCTAssertEqual(label.bounds.height, 0)
}

/* corner radius */

func testThat_cornerRadius_correctlyConfigures() {
let view = UIView()

view.configureFrame { maker in
maker.cornerRadius(100)
}
XCTAssertEqual(view.layer.cornerRadius, 100)
}

func testThat_cornerRadiusWithHalfWidth_correctlyConfigures() {
let view = UIView()

view.configureFrame { maker in
maker.width(100)
maker.cornerRadius(byHalf: .width)
}
XCTAssertEqual(view.layer.cornerRadius, 50)
}

func testThat_cornerRadiusWithHalfHeight_correctlyConfigures() {
let view = UIView()

view.configureFrame { maker in
maker.height(100)
maker.cornerRadius(byHalf: .height)
}
XCTAssertEqual(view.layer.cornerRadius, 50)
}
}

0 comments on commit 2a2c43b

Please sign in to comment.