Commit 0ae3220c by Daniel Dahan

working on GridView, latest additions for Vertical alignment

parent 55d70ff5
...@@ -40,7 +40,9 @@ class ViewController: UIViewController { ...@@ -40,7 +40,9 @@ class ViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareHorizontalGridViewExample() // prepareHorizontalGridViewExample()
// prepareVerticalGridViewExample()
prepareSmallCardViewExample()
} }
...@@ -49,6 +51,48 @@ class ViewController: UIViewController { ...@@ -49,6 +51,48 @@ class ViewController: UIViewController {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
} }
/// Prepares the small card example.
private func prepareSmallCardViewExample() {
var image: UIImage? = UIImage.imageWithColor(MaterialColor.blueGrey.darken4, size: CGSizeMake(100, 100))
let imageView: MaterialView = MaterialView()
imageView.grid = .Grid3
imageView.image = image
let contentView: GridView = GridView()
contentView.grid = .Grid9
contentView.unifiedHeight = 40
contentView.backgroundColor = MaterialColor.blue.base
let titleGridView: GridView = GridView()
titleGridView.grid = .Grid9
titleGridView.spacing = 8
titleGridView.unifiedHeight = 40
image = UIImage(named: "ic_more_vert_white")?.imageWithRenderingMode(.AlwaysTemplate)
let moreButton: FlatButton = FlatButton()
moreButton.grid = .Grid2
moreButton.pulseColor = MaterialColor.blueGrey.darken4
moreButton.tintColor = MaterialColor.blueGrey.darken4
moreButton.backgroundColor = MaterialColor.green.base
moreButton.setImage(image, forState: .Normal)
moreButton.setImage(image, forState: .Highlighted)
let titleLabel: MaterialLabel = MaterialLabel()
titleLabel.grid = .Grid7
titleLabel.text = "Material GridView ahskjdha sjdha sjkdhas jkhd "
titleLabel.textColor = MaterialColor.blueGrey.darken4
titleGridView.views = [titleLabel, moreButton]
contentView.views = [titleGridView]
let gridView: GridView = GridView(frame: CGRectMake(16, 100, view.bounds.width - 32, 100))
gridView.unifiedHeight = 100
gridView.views = [imageView, contentView]
view.addSubview(gridView)
}
/// Prepares the Horizontal GridView example. /// Prepares the Horizontal GridView example.
private func prepareHorizontalGridViewExample() { private func prepareHorizontalGridViewExample() {
var image: UIImage? = UIImage(named: "ic_flash_auto_white")?.imageWithRenderingMode(.AlwaysTemplate) var image: UIImage? = UIImage(named: "ic_flash_auto_white")?.imageWithRenderingMode(.AlwaysTemplate)
...@@ -97,5 +141,62 @@ class ViewController: UIViewController { ...@@ -97,5 +141,62 @@ class ViewController: UIViewController {
MaterialLayout.alignFromTop(view, child: gridView) MaterialLayout.alignFromTop(view, child: gridView)
MaterialLayout.alignToParentHorizontally(view, child: gridView) MaterialLayout.alignToParentHorizontally(view, child: gridView)
} }
internal func handleButton() {
print("Clicked Button")
}
/// Prepares the Vertical GridView example.
private func prepareVerticalGridViewExample() {
var image: UIImage? = UIImage(named: "ic_flash_auto_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn1: FlatButton = FlatButton()
// btn1.grid = .Grid2
btn1.pulseColor = MaterialColor.blueGrey.darken4
btn1.tintColor = MaterialColor.blueGrey.darken4
btn1.backgroundColor = MaterialColor.grey.lighten3
btn1.setImage(image, forState: .Normal)
btn1.setImage(image, forState: .Highlighted)
btn1.addTarget(self, action: "handleButton", forControlEvents: .TouchUpInside)
image = UIImage(named: "ic_flash_off_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn2: FlatButton = FlatButton()
// btn2.grid = .Grid3
btn2.pulseColor = MaterialColor.blueGrey.darken4
btn2.tintColor = MaterialColor.blueGrey.darken4
btn2.backgroundColor = MaterialColor.grey.lighten3
btn2.setImage(image, forState: .Normal)
btn2.setImage(image, forState: .Highlighted)
image = UIImage(named: "ic_flash_on_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn3: FlatButton = FlatButton()
btn3.pulseColor = MaterialColor.blueGrey.darken4
btn3.tintColor = MaterialColor.blueGrey.darken4
btn3.backgroundColor = MaterialColor.grey.lighten3
btn3.setImage(image, forState: .Normal)
btn3.setImage(image, forState: .Highlighted)
let label1: MaterialLabel = MaterialLabel()
label1.text = "A"
label1.backgroundColor = MaterialColor.blue.base
let label2: MaterialLabel = MaterialLabel()
label2.text = "B"
// label2.grid = .Grid2
label2.backgroundColor = MaterialColor.blue.base
let gridView: GridView = GridView()
// let gridView: GridView = GridView(frame: CGRectMake(0, 100, view.bounds.width, 100))
gridView.grid = .Grid12
gridView.layout = .Vertical
// gridView.spacing = 32
// gridView.unifiedHeight = 40
gridView.views = [btn1, btn2, label2]
view.addSubview(gridView)
gridView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: gridView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: gridView)
MaterialLayout.height(view, child: gridView, height: 400)
}
} }
...@@ -120,6 +120,7 @@ public class GridView : MaterialView { ...@@ -120,6 +120,7 @@ public class GridView : MaterialView {
let g: Int = grid.rawValue let g: Int = grid.rawValue
let w: CGFloat = (width - spacing) / CGFloat(g) let w: CGFloat = (width - spacing) / CGFloat(g)
let h: CGFloat = (height - spacing) / CGFloat(g)
if let v: Array<GridCell> = views { if let v: Array<GridCell> = views {
var n: Int = 0 var n: Int = 0
for var i: Int = 0, l: Int = v.count; i < l; ++i { for var i: Int = 0, l: Int = v.count; i < l; ++i {
...@@ -128,6 +129,8 @@ public class GridView : MaterialView { ...@@ -128,6 +129,8 @@ public class GridView : MaterialView {
let m: Int = cell.grid.rawValue let m: Int = cell.grid.rawValue
if .Horizontal == layout { if .Horizontal == layout {
view.frame = CGRectMake(CGFloat(i + n) * w + spacing, 0, (w * CGFloat(m)) - spacing, 0 < unifiedHeight ? unifiedHeight : view.intrinsicContentSize().height) view.frame = CGRectMake(CGFloat(i + n) * w + spacing, 0, (w * CGFloat(m)) - spacing, 0 < unifiedHeight ? unifiedHeight : view.intrinsicContentSize().height)
} else {
view.frame = CGRectMake(0, CGFloat(i + n) * h + spacing, view.intrinsicContentSize().width, (h * CGFloat(m)) - spacing)
} }
view.removeFromSuperview() view.removeFromSuperview()
addSubview(view) addSubview(view)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment