Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playground examples #134

Merged
merged 2 commits into from
Jun 8, 2017
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
10 changes: 10 additions & 0 deletions BrickKit.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//: Playground - noun: a place where people can play

import UIKit
import BrickKit
import PlaygroundSupport

struct Fruit {
let name: String
}

var fruits: [Fruit] = []

let brickView = BrickCollectionView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
brickView.backgroundColor = .white

//Add the set the live view
PlaygroundPage.current.liveView = brickView

fruits.append(Fruit(name: "Apple"))
fruits.append(Fruit(name: "Banana"))
fruits.append(Fruit(name: "Cherry"))

let labelBrick = GenericBrick<UILabel>("FRUIT", configureView: { view, cell in
view.text = fruits[cell.index].name
view.textAlignment = .center
})

let section = BrickSection(backgroundColor: .lightGray, bricks: [
labelBrick
], inset: 8, edgeInsets: UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16))

labelBrick.repeatCount = fruits.count
brickView.setSection(section)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' display-mode='raw'>
<timeline fileName='timeline.xctimeline'/>
</playground>
21 changes: 21 additions & 0 deletions Example/Playgrounds/LabelBrickPlayground.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//: Playground - noun: a place where people can play

import UIKit
import BrickKit
import PlaygroundSupport

let brickView = BrickCollectionView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
brickView.backgroundColor = UIColor.white

let configureBlock: ((LabelBrickCell) -> Void) = { cell in
cell.label.textAlignment = .center
}

let section = BrickSection(backgroundColor: .lightGray, bricks: [
LabelBrick(text: "LABEL BRICK", configureCellBlock: configureBlock)
], edgeInsets: UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16))

brickView.setSection(section)

//Add the set the live view
PlaygroundPage.current.liveView = brickView
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,6 @@ class ViewController: BrickViewController {
override func viewDidLoad() {
super.viewDidLoad()

// Register the bricks you are going to use
self.registerBrickClass(LabelBrick.self)

let section = BrickSection(bricks: [
LabelBrick(text: "LABEL BRICK")
])
Expand All @@ -374,7 +371,7 @@ let section = BrickSection(bricks: [
LabelBrick(text: "LABEL BRICK LABEL BRICK LABEL BRICK LABEL BRICK")
])
```

Try it in the LabelBrickPlayground.

### BrickDimension
To setup the dimensions of a brick, please refer to [BRICK_DIMENSION.md](Docs\BRICK_DIMENSION.md).
Expand All @@ -388,21 +385,18 @@ import BrickKit

class ViewController: BrickViewController {

var fruits = Array<Fruit>()
var fruits: [Fruit] = []

override func viewDidLoad() {
super.viewDidLoad()

products.append(Fruit("Apple"))
products.append(Fruit("Banana"))
products.append(Fruit("Cherry"))

// Register the bricks you are going to use
self.registerBrickClass(LabelBrick.self)
fruits.append(Fruit(name: "Apple"))
fruits.append(Fruit(name: "Banana"))
fruits.append(Fruit(name: "Cherry"))

let section = BrickSection(bricks: [
LabelBrick("FRUIT", text: "BRICK 1")
])
])

section.repeatCountDataSource = self

Expand All @@ -418,6 +412,7 @@ extension ViewController: BrickRepeatCountDataSource {
}
}
```
Try it in the BrickRepeatCountPlayground.

## Layout

Expand Down