Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion PinLayout.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "PinLayout"
s.version = "1.0.5"
s.version = "1.0.6"
s.summary = "Swift manual views layouting without auto layout, no magic, pure code, full control. Concise syntax, readable & chainable."

# This description is used to generate tags and improve search results.
Expand Down
6 changes: 5 additions & 1 deletion PinLayout/Helpers/Coordinates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Coordinates {
return CGPoint(x: view.frame.minX + view.frame.width, y: view.frame.minY + view.frame.height)
}

static var displayScale: CGFloat = UIScreen.main.scale
fileprivate static var displayScale: CGFloat = UIScreen.main.scale

static func adjustRectToDisplayScale(_ rect: CGRect) -> CGRect {
return CGRect(x: roundFloatToDisplayScale(rect.origin.x),
Expand All @@ -89,3 +89,7 @@ class Coordinates {
return CGFloat(ceilf(Float(pointValue * displayScale))) / displayScale
}
}

public func setUnitTest(displayScale: CGFloat) {
Coordinates.displayScale = displayScale
}
10 changes: 2 additions & 8 deletions PinLayout/PinLayoutImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1087,10 +1087,7 @@ extension PinLayoutImpl {
let marginToDistribute = newWidth! - sizeThatFits.width

// Distribute the width change to Margins
if let _ = _left, let _ = _right {
marginLeft = (marginLeft ?? 0) + (marginToDistribute / 2)
marginRight = (marginRight ?? 0) + (marginToDistribute / 2)
} else if let _ = _left {
if let _ = _left {
marginRight = (marginRight ?? 0) + marginToDistribute
} else if let _ = _right {
marginLeft = (marginLeft ?? 0) + marginToDistribute
Expand All @@ -1101,10 +1098,7 @@ extension PinLayoutImpl {
let marginToDistribute = newHeight! - sizeThatFits.height

// Distribute the height change to Margins
if let _ = _top, let _ = _bottom {
marginTop = (marginTop ?? 0) + (marginToDistribute / 2)
marginBottom = (marginBottom ?? 0) + (marginToDistribute / 2)
} else if let _ = _top {
if let _ = _top {
marginBottom = (marginBottom ?? 0) + marginToDistribute
} else if let _ = _bottom {
marginTop = (marginTop ?? 0) + marginToDistribute
Expand Down
2 changes: 1 addition & 1 deletion PinLayoutSample/.ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.5
2.3.3
11 changes: 2 additions & 9 deletions PinLayoutSample/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@ workspace 'PinLayoutSample.xcworkspace'

target 'PinLayoutSample' do
project 'PinLayoutSample.xcodeproj'
#pod 'YogaKit', '~> 1.1'

# Debug only
pod 'Reveal-SDK', :configurations => ['Debug']
pod 'SwiftLint'
pod 'Reveal-SDK', :configurations => ['Debug']
pod 'SwiftLint'
end

#target 'PinLayoutTests' do
# project '../PinLayout.xcodeproj'
# pod 'Quick'
# pod 'Nimble'
#end
8 changes: 4 additions & 4 deletions PinLayoutSample/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
PODS:
- Reveal-SDK (8)
- SwiftLint (0.18.1)
- SwiftLint (0.19.0)

DEPENDENCIES:
- Reveal-SDK
- SwiftLint

SPEC CHECKSUMS:
Reveal-SDK: 43be4e662864e937960d0d04d005135e29c4e53b
SwiftLint: b467d08f5b25dc3b3cfed243d8e1b74b91714c67
SwiftLint: 3537a05b34060e78e7510f04fb7537d738247803

PODFILE CHECKSUM: 59a9a3ad8ae4f0bb64a6dadf661a354de61b0d83
PODFILE CHECKSUM: 500d466f69a20c6292b04b938d6dce3e1f8f6e8b

COCOAPODS: 1.1.1
COCOAPODS: 1.2.1.beta.1
256 changes: 218 additions & 38 deletions PinLayoutTests/AdjustSizeSpec.swift

Large diffs are not rendered by default.

32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Swift manual views layouting without auto layout, no magic, pure code, full cont
* Concise syntax. Layout most views using a single line.

* Stateless
* The layout system doesn’t add any stored properties to UIViews. It simply computes the UIView.frame property, one view at a time.
* PinLayout doesn’t add any stored properties to UIViews. It simply computes the UIView.frame property, one view at a time.
* Since it is stateless, it can be used with any other layout framework without conflicts.
Each view can use the layout system that better suit it (PinLayout, constraints, flexbox, grids, …)
A view can be layouted using PinLayout and later with another method/framework.
Expand All @@ -55,6 +55,8 @@ A view can be layouted using PinLayout and later with another method/framework.

* Before applying the new sets of attributes, PinLayout always start with the view’s current frame. So it’s possible to set the view’s size during the initialization (ex: view.pin.width(100).height(200)), and later only position the view (ex: view.pin.top(10).left(20)). This makes PinLayout really animation friendly.

* Not too intrusive. PinLayout only adds three properties to existing iOS classes: `UIView.pin`, `UIView.anchor` and `UIView.edge`

* Minimize as much as possible calculations and constants when layouting views.

* Methods match as much as possible other layouting systems, including CSS, flexbox, reactive Flexbox, …
Expand Down Expand Up @@ -118,6 +120,8 @@ override func layoutSubviews() {
}
```

:pushpin: This example and some other examples are available in the **PinLayoutSample** project. Please note that you must do a `pod install` before running the sample project.

<br/>


Expand Down Expand Up @@ -692,6 +696,30 @@ Warnings can be disabled in debug mode too by setting the boolean PinLayoutLogCo

<br/>

## PinLayout style guide

* You should always specifies methods in the same order, it makes layout lines easier to understand. Here is our prefered ordering:
`view.pin.[EDGE|ANCHOR|RELATIVE].[WIDTH|HEIGHT|SIZE].[pinEdges()].[MARGINS].[sizeToFit()]`

This order reflect the logic inside PinLayout. `pinEdges()` is applied before margins and margins are applied before `sizeToFit()`.

```javascript
view.pin.top().left(10%).margin(10, 12, 10, 12)
view.pin.left().width(100%).pinEdges().marginHorizontal(12)
view.pin.left().right().margin(0, 12).sizeToFit()
view.pin.width(100).height(100%)
```

* If the layout line is too long, you can split in multiple lines:

```
textLabel.pin.below(of: titleLabel)
.right(of: statusIcon).left(of: accessoryView)
.above(of: button).marginHorizontal(10)
```

<br/>

## More examples<a name="more_examples"></a>

### Adjust to container size
Expand Down Expand Up @@ -746,7 +774,7 @@ Cell D:
<br>

## Comments, ideas, suggestions, issues, ....
For any (I really meant it) **comments**, **ideas**, **suggestions**, **issues**, simply open an [issue](https://github.com/mirego/PinLayout/issues).
For any **comments**, **ideas**, **suggestions**, **issues**, simply open an [issue](https://github.com/mirego/PinLayout/issues).

<br>

Expand Down