Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshaber/SwiftBox
Flexbox in Swift, using Facebook's css-layout.
https://github.com/joshaber/SwiftBox
Last synced: about 1 month ago
JSON representation
Flexbox in Swift, using Facebook's css-layout.
- Host: GitHub
- URL: https://github.com/joshaber/SwiftBox
- Owner: joshaber
- License: other
- Created: 2015-02-02T01:42:30.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-01-23T09:29:16.000Z (almost 8 years ago)
- Last Synced: 2024-10-30T06:54:56.575Z (2 months ago)
- Language: Swift
- Size: 108 KB
- Stars: 810
- Watchers: 19
- Forks: 57
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - SwiftBox - Flexbox in Swift, using Facebook's css-layout. (Layout / Other Hardware)
- awesome-ios-star - SwiftBox - Flexbox in Swift, using Facebook's css-layout. (Layout / Other Hardware)
- awesome-swift-cn - SwiftBox - Flexbox in Swift, using Facebook's css-layout. (Libs / Layout)
README
# SwiftBox
A Swift wrapper around Facebook's [implementation](https://github.com/facebook/css-layout) of CSS's flexbox.
## Example
```swift
let parent = Node(size: CGSize(width: 300, height: 300),
childAlignment: .Center,
direction: .Row,
children: [
Node(flex: 75,
margin: Edges(left: 10, right: 10),
size: CGSize(width: 0, height: 100)),
Node(flex: 15,
margin: Edges(right: 10),
size: CGSize(width: 0, height: 50)),
Node(flex: 10,
margin: Edges(right: 10),
size: CGSize(width: 0, height: 180)),
])let layout = parent.layout()
println(layout)//{origin={0.0, 0.0}, size={300.0, 300.0}}
// {origin={10.0, 100.0}, size={195.0, 100.0}}
// {origin={215.0, 125.0}, size={39.0, 50.0}}
// {origin={264.0, 60.0}, size={26.0, 180.0}}
```Alternatively, you could apply the layout to a view hierarchy (after ensuring Auto Layout is off):
```swift
layout.apply(someView)
```See [SwiftBoxDemo](SwiftBoxDemo/SwiftBoxDemo) for a demo.