To run the example project, clone the repo, and run pod install
from the Example directory first.
ClipLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ClipLayout'
It's easy to read and takes only few lines of code to make complex layout.
It's the fastest Layout Engine compared to other popular libraries.
You don't have to specify the size. ClipLayout will try to estimate how much space the view needs for it's content. And place subview in the center of the superview by default.
If views don't fit on the screen their size will be adjusted.
It's easy to animate changes in Clip Layout. Just alter the layout however you want and call clip.invalidateLayout()
on the superview in animation context.
view.clip.withDistribution(flag ? .column : .row)
UIView.animate(withDuration: 0.8) {
self.superview.clip.invalidateLayout()
}
RTL support is enabled by default on any view. If you use distribution == .row
, views will be mirrored in horizontal axis. To disable RTL set supportRightToLeft = false
.
You can mix and match ClipLayout with Auto Layout or any other framework. You only need to specify property on UIView enable = true
on parent and descendant views that use Clip Layout.
You set up the Cell that conforms to DataBinder and inherits ClipCell
class DynamicCell: ClipCell, DataBinder {
func set(data: SomeData) {
}
}
Then you just use ClipCollectionView with your cell as a generic parameter and everything will be automaticaly handled.
You can optionaly set maxSize
to restrict cell to some size, it defaults to CollectionView width and unlimited height.
To set data use data
property.
let view = ClipCollectionView<DynamicCell>(collectionViewLayout: UICollectionViewFlowLayout())
view.data = [SomeData]()
In swift you can use both.
objc:
[view configureWithBlock:^(ClipLayout *clip) {
clip.wantsSize = CGSizeMake(100, 100);
clip.alignment.vertical = ClipAlignmentHead;
clip.distribution = ClipDistributionRow;
}];
swift:
view.clip.enabled().withWidth(100).withHeight(100).verticallyAligned(.head).withDistribution(.row)
Denis Litvin, den.litvinn@gmail.com
ClipLayout is available under the MIT license. See the LICENSE file for more info.