-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from isair/feature/many-features
Many Features
- Loading branch information
Showing
8 changed files
with
265 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// Functions.swift | ||
// ManualLayout | ||
// | ||
// Created by Baris Sencan on 26/02/15. | ||
// Copyright (c) 2015 Baris Sencan. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
//MARK: - Insetting | ||
|
||
public func inset(view: UIView, amount: CGFloat) -> CGRect { | ||
return inset(view.frame, amount) | ||
} | ||
|
||
public func inset(layer: CALayer, amount: CGFloat) -> CGRect { | ||
return inset(layer.frame, amount) | ||
} | ||
|
||
public func inset(rect: CGRect, amount: CGFloat) -> CGRect { | ||
return CGRectInset(rect, amount, amount) | ||
} | ||
|
||
public func inset(view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect { | ||
return inset(view.frame, dx, dy) | ||
} | ||
|
||
public func inset(layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect { | ||
return inset(layer.frame, dx, dy) | ||
} | ||
|
||
public func inset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect { | ||
return CGRectInset(rect, dx, dy) | ||
} | ||
|
||
public func inset(view: UIView, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect { | ||
return inset(view.frame, top, left, bottom, right) | ||
} | ||
|
||
public func inset(layer: CALayer, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect { | ||
return inset(layer.frame, top, left, bottom, right) | ||
} | ||
|
||
public func inset(rect: CGRect, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect { | ||
return CGRect( | ||
x: rect.origin.x + left, | ||
y: rect.origin.y + top, | ||
width: rect.size.width - left - right, | ||
height: rect.size.height - top - bottom) | ||
} | ||
|
||
// MARK: - Offsetting | ||
|
||
public func offset(view: UIView, amount: CGFloat) -> CGRect { | ||
return offset(view.frame, amount) | ||
} | ||
|
||
public func offset(layer: CALayer, amount: CGFloat) -> CGRect { | ||
return offset(layer.frame, amount) | ||
} | ||
|
||
public func offset(rect: CGRect, amount: CGFloat) -> CGRect { | ||
return CGRectOffset(rect, amount, amount) | ||
} | ||
|
||
public func offset(view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect { | ||
return offset(view.frame, dx, dy) | ||
} | ||
|
||
public func offset(layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect { | ||
return offset(layer.frame, dx, dy) | ||
} | ||
|
||
public func offset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect { | ||
return CGRectOffset(rect, dx, dy) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// OperatorOverloads.swift | ||
// ManualLayout | ||
// | ||
// Created by Baris Sencan on 26/02/15. | ||
// Copyright (c) 2015 Baris Sencan. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
infix operator =~ { associativity right precedence 150 } | ||
|
||
public func =~ (inout point: CGPoint, pointTuple: (CGFloat, CGFloat)) -> CGPoint { | ||
point = CGPoint(x: pointTuple.0, y: pointTuple.1) | ||
return point | ||
} | ||
|
||
public func =~ (inout size: CGSize, sizeTuple: (CGFloat, CGFloat)) -> CGSize { | ||
size = CGSize(width: sizeTuple.0, height: sizeTuple.1) | ||
return size | ||
} | ||
|
||
public func =~ (inout rect: CGRect, rectTuple: (CGFloat, CGFloat, CGFloat, CGFloat)) -> CGRect { | ||
rect = CGRect(x: rectTuple.0, y: rectTuple.1, width: rectTuple.2, height: rectTuple.3) | ||
return rect | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// HelperFunctionTests.swift | ||
// ManualLayout | ||
// | ||
// Created by Baris Sencan on 26/02/15. | ||
// Copyright (c) 2015 Baris Sencan. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
import ManualLayout | ||
|
||
class HelperFunctionTests: XCTestCase { | ||
var view = UIView(frame: CGRectZero) | ||
let defaultFrame = CGRect(x: 1, y: 3, width: 6, height: 8) | ||
|
||
override func setUp() { | ||
view.frame = defaultFrame | ||
} | ||
|
||
func testInsetSingleArg() { | ||
view.frame = inset(view, 1) | ||
XCTAssertEqual( | ||
view.frame, | ||
CGRect(x: 2, y: 4, width: 4, height: 6), | ||
"insetting with amount should inset correctly") | ||
} | ||
|
||
func testInsetTwoArg() { | ||
view.frame = inset(view, 1, 2) | ||
XCTAssertEqual( | ||
view.frame, | ||
CGRect(x: 2, y: 5, width: 4, height: 4), | ||
"insetting with dx and dy should inset correctly") | ||
} | ||
|
||
func testInsetFourArg() { | ||
view.frame = inset(view, 1, 2, 3, 4) | ||
XCTAssertEqual( | ||
view.frame, | ||
CGRect(x: 3, y: 4, width: 0, height: 4), | ||
"insetting with four arguments should inset correctly") | ||
} | ||
|
||
func testOffsetSingleArg() { | ||
view.frame = offset(view, 1) | ||
XCTAssertEqual( | ||
view.frame, | ||
CGRect(x: 2, y: 4, width: 6, height: 8), | ||
"offsetting with amount should offset correctly") | ||
} | ||
|
||
func testOffsetTwoArg() { | ||
view.frame = offset(view, 1, 2) | ||
XCTAssertEqual( | ||
view.frame, | ||
CGRect(x: 2, y: 5, width: 6, height: 8), | ||
"offsetting with dx and dy should offset correctly") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// OperatorTests.swift | ||
// ManualLayout | ||
// | ||
// Created by Baris Sencan on 26/02/15. | ||
// Copyright (c) 2015 Baris Sencan. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
import ManualLayout | ||
|
||
class OperatorTests: XCTestCase { | ||
var view = UIView(frame: CGRectZero) | ||
|
||
override func setUp() { | ||
view.frame = CGRectZero | ||
} | ||
|
||
func testPointAssignment() { | ||
view.origin =~ (1, 3) | ||
XCTAssertEqual(view.origin, CGPoint(x: 1, y: 3), "origin should be at (1, 3)") | ||
} | ||
|
||
func testSizeAssignment() { | ||
view.size =~ (5, 7) | ||
XCTAssertEqual(view.size, CGSize(width: 5, height: 7), "size should be (5, 7)") | ||
} | ||
|
||
func testRectAssignment() { | ||
view.frame =~ (1, 3, 5, 7) | ||
XCTAssertEqual( | ||
view.frame, | ||
CGRect(x: 1, y: 3, width: 5, height: 7), | ||
"frame should be at (1, 3) and of size (5, 7)") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters