Released on 2018-06-28
The recent changes to PinLayout that enable the layout of CALayer has impacted the layout of UIViews.
Released on 2018-06-26
PinLayout can now layouts CALayer's. All PinLayout's properties and methods are available, with the following exceptions:
sizeToFit(:FitType)
is not supported. Support forsizeToFit(:FitType)
can be added to your custom CALayer subclasses, just make those layers conform to theSizeCalculable
protocol and implement the two required functions.CALayer.pin.safeArea
property is not available.aspectRatio()
with no parameters
See CALayer Support documentation for more information
- Added by Antoine Lamy in Pull Request #151
Released on 2018-06-19
Refactoring to avoid having to deal directly with view types, making it easier to extend layouting to other APIs (e.g: CALayer)
- Added by Antoine Lamy in Pull Request #148
Released on 2018-06-12
PinLayout is now part of the same organization as other open source projects related to layout using Swift.
Released on 2018-06-05
The following methods are useful to adjust view's width and/or height to wrap all its subviews. These methods also adjust subviews position to create a tight wrap.
Methods:
wrapContent()
wrapContent(padding: CGFloat)
wrapContent(padding: UIEdgeInsets)
Adjust the view's width and height to wrap all its subviews. The method also adjusts subviews position to create a tight wrap. It is also possible to specify an optional padding around all subviews.wrapContent(:WrapType)
wrapContent(:WrapType, padding: CGFloat)
wrapContent(:WrapType, padding: UIEdgeInsets)
Adjust the view's width AND/OR height to wrap all its subviews. WrapType values are.horizontally
/.vertically
/.all
It is also possible to specify an optional padding around all subviews.
See documentation for more information
Added by Luc Dion in Pull Request #141
Released on 2018-05-26
Add the support of Objective-C to macOS and tvOS.
Added by Luc Dion in Pull Request #138
Released on 2018-04-25
These methods and properties are now accessible from Objective-C:
Pin.layoutDirection
Pin.safeAreaInsetsDidChangeMode
Pin.logWarnings
Pin.initPinLayout()
Pin.layoutDirection()
Added by Luc Dion in Pull Request #135
Released on 2018-04-23
Changes:
-
On iOS 8, PinLayout compatibility support of UIView.safeAreaInsetsDidChange was causing issues with the device's virtual keyboard. PinLayout still support UIView.pin.safeArea on this iOS release, but UIView.safeAreaInsetsDidChange won't be called on iOS 8
-
Fix issue with "New Relic" framework: Add a Pin.initPinLayout() that can be called to initialize PinLayout before the "New Relic" framework is initialized. "New Relic" is conflicting with other popular frameworks including Mixpanel, ReactiveCocoa, Aspect, ..., and PinLayout. To fix the issue,
Pin.initPinLayout()
must be called BEFORE initializing "New Relic" withNewRelic.start(withApplicationToken:"APP_TOKEN")
. See here for more information regarding this issue #130
Added by Luc Dion in Pull Request #134
Released on 2018-04-20
PinLayout now support macOS.
PinLayout support of macOS is not complete at 100%, see here the particularities of the current implementation:
-
PinLayout support only views that have a parent (superview) using a flipped coordinate system, i.e. views for which the computed property
var isFlipped: Bool
returns true. In a flipped coordinate system, the origin is in the upper-left corner of the view and y-values extend downward. UIKit use this coordinate system. In a non-flipped coordinate system (default mode), the origin is in the lower-left corner of the view and positive y-values extend upward. See Apple's documentation for more information aboutNSView.isFlipped
. The support of non-flipped coordinate system will be added soon. -
These methods are currently not supported on macOS, but they will be implemented soon:
sizeToFit(:FitType)
(Coming soon)aspectRatio()
with no parameters (Coming soon)
-
UIView.pin.safeArea
property is not available, AppKit doesn't have an UIView.safeAreaInsets equivalent.
All other PinLayout's methods and properties are available on macOS!
Added by Luc Dion in Pull Request #131
The PinLayout license has been changed from BSD 3-clause "New" to MIT License.
Released on 2018-03-22
PinLayout can handle easily iOS 11 UIView.safeAreaInsets, but it goes further by supporting safeAreaInsets for previous iOS releases (including iOS 7/8/9/10) by adding a property UIView.pin.safeArea. PinLayout also extend the support of UIView.safeAreaInsetsDidChange() callback on iOS 7/8/9/10.
See UIView.pin.safeArea Documentation for more details.
Added by Luc Dion in Pull Request #125
-
all(_ insets: UIEdgeInsets)
-
horizontally(_ insets: UIEdgeInsets)
-
vertically(_ insets: UIEdgeInsets)
-
top(_ insets: UIEdgeInsets)
-
bottom(_ insets: UIEdgeInsets)
-
left(_ insets: UIEdgeInsets)
-
right(_ insets: UIEdgeInsets)
See Layout using distances from superview’s edges for more details.
-
marginTop(_ percent: Percent)
-
marginLeft(_ percent: Percent)
-
marginBottom(_ percent: Percent)
-
marginLeft(_ percent: Percent)
-
marginStart(_ percent: Percent)
-
marginEnd(_ percent: Percent)
-
marginHorizontal(_ percent: Percent)
-
marginVertical(_ percent: Percent)
-
margin(_ percent: Percent)
-
margin(_ vertical: Percent, _ horizontal: Percent)
-
margin(_ top: Percent, _ horizontal: Percent, _ bottom: Percent)
-
margin(_ top: Percent, _ left: Percent, _ bottom: Percent, _ right: Percent)
Released on 2018-02-18
Until now UIView.pin
was used to layout views, but there's also another property called UIView.pinFrame
that does something slightly different in situations where the view has a transform (UIView.transform
, scaling, rotation, ...).
-
pin
: Set the position and the size of the non-transformed view. The size and position is applied before the transform. This is particularly useful when you want to animate a view using a transform without modifying its layout. -
.pinFrame
: Set the position and the size on the transformed view. The size and position is applied after the transform.
See https://github.com/layoutBox/PinLayout#uiviews-transforms for more informations.
Added by Luc Dion in Pull Request #122
Released on 2018-01-20
- Handle layout relative to a view with a transform and/or a modified anchorPoint.
Added by Luc Dion in Pull Request #116
Released on 2018-01-19
-
Fix an issue that was affecting UIScrollViews. PinLayout now set only the bounds's size and keep the origin.
Added by Luc Dion in Pull Request #115 -
Handle correctly view's
layer.anchorPoint
. PinLayout now update correctly the view position when the view's layer.anchorPoint has been modified, i.e. when it is not its default value (0.5, 0.5). Added by Luc Dion in Pull Request #114
Released on 2018-01-12
Add methods:
-
all(_ value: CGFloat)
The value specifies the top, bottom, left and right edges distance from the superview's corresponding edge in pixels. Similar to callingview.top(value).bottom(value).left(value).right(value)
. -
horizontally(_ value: CGFloat)
/horizontally(_ percent: Percent)
The value specifies the left and right edges on its superview's corresponding edges in pixels (or in percentage of its superview's width).
Similar to callingview.left(value).right(value)
. -
vertically(_ value: CGFloat)
/vertically(_ percent: Percent)
The value specifies the ** top and bottom edges** on its superview's corresponding edges in pixels (or in percentage of its superview's height).
Similar to callingview.top(value).bottom(value)
.- Added by Olivier Pineau in Pull Request #111
Released on 2017-12-28
- PinLayout now handle correctly more situations with view with transforms.
Released on 2017-12-28
- PinLayout now handle correctly parents (superviews) with transforms.
Released on 2017-12-22
-
POSSIBLE BREAKING CHANGE: PinLayout now keeps UIView's transform (scale, rotation, ...)
Previously any view's transform was altered after layouting the view with PinLayout. Now PinLayout won't affect the view's transforms.For people not using transforms, this should be a non-breaking change. If someone is using transforms with PinLayout, this may change the behavior, although I think this will produce the expected results (ie, transforms not being affected/altered by layout).
- Add
layout()
method to support Xcode playgrounds PinLayout layouts views immediately after the line containing.pin
has been fully executed, thanks to ARC (Automatic Reference Counting) this works perfectly on iOS/tvOS/macOS simulators and devices. But in Xcode Playgrounds, ARC doesn't work as expected, object references are kept much longer. This is a well-documented issue. The impact of this problem is that PinLayout doesn't layout views at the time and in the order required. To handle this situation in playgrounds it is possible to call thelayout()
method to complete the layout.
See PinLayout in Xcode Playgrounds documentation for more information
-
BREAKING CHANGE:
fitSize()
is now deprecated. The newsizeToFit(:FitType)
should be used instead. -
New method
sizeToFit(_ fitType: FitType)
-
sizeToFit(_ fitType: FitType)
The method adjust the view's size based on the view'ssizeThatFits()
method result. PinLayout will adjust either the view's width or height based on thefitType
parameter value.Notes:
- If margin rules apply, margins will be applied when determining the reference dimension (width/height).
- The resulting size will always respect
minWidth
/maxWidth
/minHeight
/maxHeight
.
Parameter
fitType
: Identify the reference dimension (width / height) that will be used to adjust the view's size. -
.width
: The method adjust the view's size based on the reference width. * If properties related to the width have been pinned (e.g: width, left & right, margins, ...), the reference width will be determined by these properties, if not the current view's width will be used. * The resulting width will always match the reference width. -
.height
: The method adjust the view's size based on the reference height. * If properties related to the height have been pinned (e.g: height, top & bottom, margins, ...), the reference height will be determined by these properties, if not the current view's height will be used. * The resulting height will always match the reference height. -
.widthFlexible
: Similar to.width
, except that PinLayout won't constrain the resulting width to match the reference width. The resulting width may be smaller of bigger depending on the view's sizeThatFits(..) method result. For example a single line UILabel may returns a smaller width if its string is smaller than the reference width. -
.heightFlexible
: Similar to.height
, except that PinLayout won't constrain the resulting height to match the reference height. The resulting height may be smaller of bigger depending on the view's sizeThatFits(..) method result.
-
Fix Carthage support
- Fix an issue that occurs with the latest Carthage version.
Add method that can pin multiples edges:
-
all()
: Pin all edges on its superview's corresponding edges (top, bottom, left, right). Similar to callingview.top().bottom().left().right()
-
horizontally()
: Pin the left and right edges on its superview's corresponding edges. Similar to callingview.left().right()
. -
vertically()
: Pin the top and bottom edges on its superview's corresponding edges. Similar to callingview.top().bottom()
.
-
Add new method
margin(_ directionalInsets: NSDirectionalEdgeInsets)
Set margins using NSDirectionalEdgeInsets. This method is particularly to set all margins using iOS 11
UIView.directionalLayoutMargins
.Available only on iOS 11 and higher.
-
Update all examples so they support iOS 11 and iPhoneX landscape mode. They use the new UIView.safeAreaInsets property.
-
PinLayout now apply correctly margins when hCenter or vCenter have been set
- hCenter: When the Horizontal Center is set, PinLayout now applies the left margin.
- vCenter: When the Vertical Center is set, PinLayout now applies the top margin.
BREAKING CHANGE: This may be a breaking change if you are using hCenter(..), vCenter(...), center(...), centerRight(...), centerLeft(...), or any other method using the center position while also using a margin.
-
Add aspectRatio methods:
aspectRatio(_ ratio: CGFloat)
:
Set the view aspect ratio. If a single dimension is set (either width or height), the aspect ratio will be used to compute the other dimension.- AspectRatio is defined as the ratio between the width and the height (width / height).
- An aspect ratio of 2 means the width is twice the size of the height.
- AspectRatio respects the min (minWidth/minHeight) and the max (maxWidth/maxHeight) dimensions of an item. Set all margins using an UIEdgeInsets. This method is particularly useful to set all margins using iOS 11 UIView.safeAreaInsets
aspectRatio(of view: UIView)
:
Set the view aspect ratio using another UIView's aspect ratio.
AspectRatio is applied only if a single dimension (either width or height) can be determined, in that case the aspect ratio will be used to compute the other dimension.
- AspectRatio is defined as the ratio between the width and the height (width / height).
- AspectRatio respects the min (minWidth/minHeight) and the max (maxWidth/maxHeight) dimensions of an item.
-
aspectRatio()
:
If the layouted view is an UIImageView, this method will set the aspectRatio using the UIImageView's image dimension.For other types of views, this method as no impact.
- Add new margin method
margin(_ insets: UIEdgeInsets)
Set all margins using an UIEdgeInsets. This method is particularly useful to set all margins using iOS 11 UIView.safeAreaInsets
Released on 2017-08-18.
- Breaking change related to hCenter(CGFloat), hCenter(percent), vCenter(CGFloat), vCenter(percent):
vCenter(_ value: CGFloat)
andvCenter(_ percent: Percent)
:
The value specifies the distance vertically of the view's center related to the superview's center in pixels. Previously it was related to the superview's top edge.hCenter(_ value: CGFloat)
andhCenter(_ percent: Percent)
:
The value specifies the distance horizontally of the view's center related to the superview's center in pixels. Previously it was related to the superview's left edge.
Previously hCenter(0)
wasn't equal to hCenter()
, same thing for vCenter(0)
. But this was an exception: top(0)
== top()
, left(0)
== left()
, right(0)
== right()
. Now thay all have the same logic.
- Add methods to pin hCenter and vCenter to any other view's edges (including the new hCenter and vCenter edges)
- New methods:
hCenter(to: edge)
Position horizontally the view's center directly on another view’s edge (left/hCenter/right)vCenter(to: edge)
Position vertically the view's center directly on another view’s edge (top/vCenter/bottom).
- New UIView's edges:
UIView.edge.hCenter
UIView.edge.vCenter
- Added by Luc Dion in Pull Request #80
- New methods:
- Warnings now display more context information
-
The class name of the view being layouted.
-
The view's current frame
-
The class name of all superviews
-
The view's Tag
Examples:
-
👉 PinLayout Warning: width(50.0%) won't be applied, the view (UIView) must be added as a sub-view before being layouted using this method.
(Layouted view info: Type: UIView, Frame: (10.0, 10.0, 20.0, 30.0), Tag: 0) -
👉 PinLayout Warning: width(-20.0) won't be applied, the width (-20.0) must be greater than or equal to zero.
(Layouted view info: Type: ItemButton, Frame: (140.0, 100.0, 100.0, 60.0), Superviews: HomeView -> UIView, Tag: 0) -
👉 PinLayout Warning: topLeft(to: .topLeft, of: (UIView, Frame: (10.0, 10.0, 10.0, 10.0))) won't be applied, the reference view (UIView, Frame: (10.0, 10.0, 10.0, 10.0)) must be added as a sub-view before being used as a reference.
(Layouted view info: Type: UIView, Frame: (140.0, 100.0, 100.0, 60.0), Superviews: UIView -> UIView, Tag: 0)
-
-
- Added a new method
fitSize()
that will replace thesizeThatFit()
method. Its prior name was creating confusion with the already existingUIView.sizeToFit()` method. sizeThatFit()
method has been marked as deprecated.
- Add Swift 4.0 support
Released on 2017-08-18.
-
Breaking change related to the following anchor's name. The change makes these anchor's name more standard:
- UIView.anchors.leftCenter has been renamed UIView.anchors.centerLeft
- UIView.anchors.rightCenter has been renamed UIView.anchors.centerRight
-
Add left to right (LTR) and right to left (RTL) language support.
Additions:- Pin.layoutDirection(_ direction: LayoutDirection)
- start(), start(_ value: CGFloat), start(_ percent: Percent)
- end(), end(_ value: CGFloat), end(_ percent: Percent)
- UIView.edge.start
- UIView.edge.end
- UIView.anchor.topStart
- UIView.anchor.topEnd
- UIView.anchor.centerStart
- UIView.anchor.centerEnd
- UIView.anchor.bottomStart
- UIView.anchor.bottomEnd
- topStart(to anchor: Anchor), topStart()
- topEnd(to anchor: Anchor), topEnd()
- centerStart(to anchor: Anchor), centerStart()
- centerEnd(to anchor: Anchor), centerEnd()
- bottomStart(to anchor: Anchor), bottomStart()
- bottomEnd(to anchor: Anchor), bottomEnd()
- before(of: UIView), before(of: [UIView])
- before(of: UIView, aligned: VerticalAlign), before(of: [UIView], aligned: VerticalAlign)
- after(of: UIView), after(of: [UIView])
- after(of: UIView, aligned: VerticalAlign), after(of: [UIView], aligned: VerticalAlign)
- marginStart(_ value: CGFloat)
- marginEnd(_ value: CGFloat)
- HorizontalAlign.start
- HorizontalAlign.end
- Added by Luc Dion in Pull Request #56
Released on 2017-07-14.
- Fix missing UIKit import. The problem was occuring while using Swift Package Manager.
Released on 2017-07-09.
- Implementation of:
Released on 2017-06-27.
- Support Xcode 9 Beta 2
- Add a Form example
Released on 2017-06-18.
- Update relative methods signatures when specifying multiple relative views.
Update the minor version due to a small breaking change with methods above(of…), below(of…), left(of…) and right(of…). They now takes either a single UIView or an Array of UIViews.
Released on 2017-06-12.
Released on 2017-06-12.
- Implementation of relative positioning using multiple relative views
- Added by Luc Dion in Pull Request #43
- The following methods can now receives one or many relative views. Useful to position a view relative to many UIViews.
above(of relativeViews: UIView...)
above(of relativeViews: UIView..., aligned: HorizontalAlignment)
below(of relativeViews: UIView...)
below(of relativeViews: UIView..., aligned: HorizontalAlignment)
left(of relativeViews: UIView...)
left(of relativeViews: UIView..., aligned: VerticalAlignment)
right(of relativeViews: UIView...)
right(of relativeViews: UIView..., aligned: VerticalAlignment)
Released on 2017-06-08.
- Add Swift Package Manager support
- Added by Luc Dion in Pull Request [#38](layoutBox#38
size(…)
methods now tries to apply the width and the height individually
Previously the size specified was applied only if both the width and height wasn’t specified. Now PinLayout will apply them individually, so if the width has been specified yet, the size’s width will be applied, else a warning will be displayed that indicate that the width won’t be applied. Same thing for the height.- Doesn’t display a warning anymore if the new specified width or height value is equal to the currently set value. This is coherent with other methods (top, left, hCenter, ….)
- Clean up
size(...)
methods source code - Add PinLayout's performance documentation
- Add 52 more unit tests. Code coverage is now 95.38%.
Released on 2017-06-06.