Commit b1776925 by Daniel Dahan

Grid example working

parent 6541b23e
{
"images" : [
{
"idiom" : "universal",
"filename" : "CosmicMindInverted.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_alarm_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_alarm_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_alarm_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
...@@ -40,9 +40,9 @@ class ViewController: UIViewController { ...@@ -40,9 +40,9 @@ class ViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareHorizontalGridViewExample() // prepareHorizontalGridViewExample()
// prepareVerticalGridViewExample() // prepareVerticalGridViewExample()
// prepareSmallCardViewExample() prepareSmallCardViewExample()
} }
...@@ -53,110 +53,87 @@ class ViewController: UIViewController { ...@@ -53,110 +53,87 @@ class ViewController: UIViewController {
/// Prepares the small card example. /// Prepares the small card example.
private func prepareSmallCardViewExample() { private func prepareSmallCardViewExample() {
var image: UIImage? = UIImage.imageWithColor(MaterialColor.blueGrey.darken4, size: CGSizeMake(100, 100)) let cardView: MaterialView = MaterialView(frame: CGRectMake(16, 100, view.bounds.width - 32, 200))
cardView.depth = .Depth1
view.addSubview(cardView)
var image: UIImage? = UIImage(named: "CosmicMindInverted")
let imageView: MaterialView = MaterialView() let imageView: MaterialView = MaterialView()
imageView.grid.column = .Grid3 imageView.grid.column = .Cell4
imageView.image = image imageView.image = image
imageView.contentsGravity = .ResizeAspectFill
cardView.addSubview(imageView)
let contentView: MaterialView = MaterialView() let contentView: MaterialView = MaterialView()
contentView.grid.column = .Grid9 contentView.grid.column = .Cell8
// contentView.backgroundColor = MaterialColor.blue.base contentView.grid.layout = .Vertical
contentView.grid.contentInsetPreset = .Square3
contentView.grid.spacing = 16
cardView.addSubview(contentView)
// let titleGridView: GridView = GridView() let titleView: MaterialView = MaterialView()
// titleGridView.grid = .Grid9 titleView.grid.column = .Cell8
// titleGridView.spacing = 8 titleView.grid.row = .Cell3
// titleGridView.unifiedHeight = 40 contentView.addSubview(titleView)
// image = UIImage(named: "ic_more_vert_white")?.imageWithRenderingMode(.AlwaysTemplate) let titleLabel: UILabel = UILabel()
// let moreButton: FlatButton = FlatButton() titleLabel.grid.column = .Cell7
// moreButton.column = .Grid2 titleLabel.text = "Title"
// moreButton.contentInsetPreset = .None titleLabel.textColor = MaterialColor.blueGrey.darken4
// moreButton.pulseColor = MaterialColor.blueGrey.darken4 titleView.addSubview(titleLabel)
// moreButton.tintColor = MaterialColor.blueGrey.darken4
//// moreButton.backgroundColor = MaterialColor.green.base image = UIImage(named: "ic_more_vert_white")?.imageWithRenderingMode(.AlwaysTemplate)
// moreButton.setImage(image, forState: .Normal) let moreButton: FlatButton = FlatButton()
// moreButton.setImage(image, forState: .Highlighted) moreButton.grid.column = .Cell1
// moreButton.contentInsetPreset = .None
// let titleView: MaterialView = MaterialView() moreButton.pulseColor = MaterialColor.blueGrey.darken4
// moreButton.tintColor = MaterialColor.blueGrey.darken4
// let titleLabel: MaterialLabel = MaterialLabel() moreButton.setImage(image, forState: .Normal)
// titleLabel.column = .Grid10 moreButton.setImage(image, forState: .Highlighted)
// titleLabel.text = "Title" titleView.addSubview(moreButton)
// titleLabel.textColor = MaterialColor.blueGrey.darken4
//// titleLabel.backgroundColor = MaterialColor.red.base
//
// let detailLabel: MaterialLabel = MaterialLabel()
// detailLabel.column = .Grid12
// detailLabel.row = .Grid1
// detailLabel.numberOfLines = 0
// detailLabel.font = RobotoFont.regularWithSize(12)
// detailLabel.text = "There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable."
// detailLabel.textColor = MaterialColor.blueGrey.darken4
//// detailLabel.backgroundColor = MaterialColor.purple.base
//
let cardView: MaterialView = MaterialView(frame: CGRectMake(16, 120, view.bounds.width - 32, 120))
cardView.depth = .Depth1
//
// let buttonView: MaterialView = MaterialView()
//
// image = UIImage(named: "ic_flash_auto_white")?.imageWithRenderingMode(.AlwaysTemplate)
// let btn1: FlatButton = FlatButton()
// btn1.pulseColor = MaterialColor.blueGrey.darken4
// btn1.tintColor = MaterialColor.blueGrey.darken4
// btn1.setImage(image, forState: .Normal)
// btn1.setImage(image, forState: .Highlighted)
//
// image = UIImage(named: "ic_flash_off_white")?.imageWithRenderingMode(.AlwaysTemplate)
// let btn2: FlatButton = FlatButton()
// btn2.pulseColor = MaterialColor.blueGrey.darken4
// btn2.tintColor = MaterialColor.blueGrey.darken4
// 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.setImage(image, forState: .Normal)
// btn3.setImage(image, forState: .Highlighted)
let detailLabel: MaterialLabel = MaterialLabel()
detailLabel.grid.row = .Cell6
detailLabel.numberOfLines = 0
detailLabel.lineBreakMode = .ByTruncatingTail
detailLabel.font = RobotoFont.regularWithSize(12)
detailLabel.text = "There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable."
detailLabel.textColor = MaterialColor.blueGrey.darken4
contentView.addSubview(detailLabel)
let alarmView: MaterialView = MaterialView()
alarmView.grid.column = .Cell8
alarmView.grid.row = .Cell3
contentView.addSubview(alarmView)
// var grid2: Grid = Grid() let alarmLabel: UILabel = UILabel()
// grid2.spacing = 8 alarmLabel.grid.column = .Cell7
// grid2.size = CGSizeMake(contentView.width - 8, 40) alarmLabel.font = RobotoFont.regularWithSize(12)
// grid2.views = [titleLabel, moreButton] alarmLabel.text = "alarm set for 2:30 pm"
// alarmLabel.textColor = MaterialColor.blueGrey.darken4
// var grid3: Grid = Grid(row: .Grid3) alarmView.addSubview(alarmLabel)
// grid3.layout = .Vertical
// grid3.size = CGSizeMake(contentView.width - 8, contentView.height)
// grid3.contentInset.left = 8
// grid3.views = [titleView, detailLabel, buttonView]
//
// var grid4: Grid = Grid()
// grid4.column = .Grid3
// grid4.spacing = 8
// grid4.size = CGSizeMake(contentView.width - 8, buttonView.height)
// grid4.views = [btn1, btn2, btn3]
print(imageView.grid.column) image = UIImage(named: "ic_alarm_white")?.imageWithRenderingMode(.AlwaysTemplate)
view.addSubview(cardView) let alarmButton: FlatButton = FlatButton()
cardView.addSubview(imageView) alarmButton.grid.column = .Cell1
cardView.addSubview(contentView) alarmButton.contentInsetPreset = .None
// contentView.addSubview(titleView) alarmButton.pulseColor = MaterialColor.blueGrey.darken4
// contentView.addSubview(detailLabel) alarmButton.tintColor = MaterialColor.blueGrey.darken4
// contentView.addSubview(buttonView) alarmButton.setImage(image, forState: .Normal)
// titleView.addSubview(titleLabel) alarmButton.setImage(image, forState: .Highlighted)
// titleView.addSubview(moreButton) alarmView.addSubview(alarmButton)
// buttonView.addSubview(btn1)
// buttonView.addSubview(btn2) cardView.grid.views = [imageView, contentView]
// buttonView.addSubview(btn3) contentView.grid.views = [titleView, detailLabel, alarmView]
titleView.grid.views = [titleLabel, moreButton]
alarmView.grid.views = [alarmLabel, alarmButton]
} }
/// 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)
let btn1: FlatButton = FlatButton() let btn1: FlatButton = FlatButton()
btn1.grid.column = .Grid3 btn1.grid.column = .Cell3
btn1.pulseColor = MaterialColor.blueGrey.darken4 btn1.pulseColor = MaterialColor.blueGrey.darken4
btn1.tintColor = MaterialColor.blueGrey.darken4 btn1.tintColor = MaterialColor.blueGrey.darken4
btn1.backgroundColor = MaterialColor.grey.lighten3 btn1.backgroundColor = MaterialColor.grey.lighten3
...@@ -166,7 +143,7 @@ class ViewController: UIViewController { ...@@ -166,7 +143,7 @@ class ViewController: UIViewController {
image = UIImage(named: "ic_flash_off_white")?.imageWithRenderingMode(.AlwaysTemplate) image = UIImage(named: "ic_flash_off_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn2: FlatButton = FlatButton() let btn2: FlatButton = FlatButton()
btn2.grid.column = .Grid3 btn2.grid.column = .Cell3
btn2.pulseColor = MaterialColor.blueGrey.darken4 btn2.pulseColor = MaterialColor.blueGrey.darken4
btn2.tintColor = MaterialColor.blueGrey.darken4 btn2.tintColor = MaterialColor.blueGrey.darken4
btn2.backgroundColor = MaterialColor.grey.lighten3 btn2.backgroundColor = MaterialColor.grey.lighten3
...@@ -176,7 +153,7 @@ class ViewController: UIViewController { ...@@ -176,7 +153,7 @@ class ViewController: UIViewController {
image = UIImage(named: "ic_flash_on_white")?.imageWithRenderingMode(.AlwaysTemplate) image = UIImage(named: "ic_flash_on_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn3: FlatButton = FlatButton() let btn3: FlatButton = FlatButton()
btn3.grid.column = .Grid3 btn3.grid.column = .Cell3
btn3.pulseColor = MaterialColor.blueGrey.darken4 btn3.pulseColor = MaterialColor.blueGrey.darken4
btn3.tintColor = MaterialColor.blueGrey.darken4 btn3.tintColor = MaterialColor.blueGrey.darken4
btn3.backgroundColor = MaterialColor.grey.lighten3 btn3.backgroundColor = MaterialColor.grey.lighten3
...@@ -192,67 +169,75 @@ class ViewController: UIViewController { ...@@ -192,67 +169,75 @@ class ViewController: UIViewController {
label2.text = "B" label2.text = "B"
label2.backgroundColor = MaterialColor.blue.base label2.backgroundColor = MaterialColor.blue.base
view.grid.size = CGSizeMake(view.bounds.width, 40) view.grid.column = .Cell9
view.grid.column = .Grid9
view.grid.spacing = 16 view.grid.spacing = 16
view.grid.contentInset.left = 16
view.grid.contentInset.right = 16
view.grid.contentInset.top = 100
view.grid.contentInset.bottom = 100
view.grid.views = [btn1, btn2, btn3] view.grid.views = [btn1, btn2, btn3]
for v in view.grid.views! {
print(v.frame)
}
}
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.row = .Cell3
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)
view.addSubview(btn1)
image = UIImage(named: "ic_flash_off_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn2: FlatButton = FlatButton()
btn2.grid.row = .Cell3
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)
view.addSubview(btn2)
image = UIImage(named: "ic_flash_on_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn3: FlatButton = FlatButton()
btn3.grid.row = .Cell3
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)
view.addSubview(btn3)
let label1: MaterialLabel = MaterialLabel()
label1.text = "A"
label1.backgroundColor = MaterialColor.blue.base
let label2: MaterialLabel = MaterialLabel()
label2.text = "B"
label2.backgroundColor = MaterialColor.blue.base
view.grid.layout = .Vertical
view.grid.row = .Cell9
view.grid.spacing = 16
view.grid.contentInset.left = 16
view.grid.contentInset.right = 16
view.grid.contentInset.top = 100
view.grid.contentInset.bottom = 100
view.grid.views = [btn1, btn2, btn3]
for v in view.grid.views! {
print(v.frame)
}
} }
//
// 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: view.bounds.height - 100)
// }
} }
...@@ -33,8 +33,6 @@ ...@@ -33,8 +33,6 @@
96442ADE1C28EF3700C3C574 /* MaterialTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96442ADD1C28EF3700C3C574 /* MaterialTableViewCell.swift */; }; 96442ADE1C28EF3700C3C574 /* MaterialTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96442ADD1C28EF3700C3C574 /* MaterialTableViewCell.swift */; };
96442ADF1C28EF3E00C3C574 /* MaterialTableViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96442ADD1C28EF3700C3C574 /* MaterialTableViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96442ADF1C28EF3E00C3C574 /* MaterialTableViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96442ADD1C28EF3700C3C574 /* MaterialTableViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9656CD0C1C6BD33700EBCEF1 /* Grid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9656CD0B1C6BD33700EBCEF1 /* Grid.swift */; }; 9656CD0C1C6BD33700EBCEF1 /* Grid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9656CD0B1C6BD33700EBCEF1 /* Grid.swift */; };
9656CD0F1C6BF28600EBCEF1 /* ColumnView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9656CD0D1C6BF28600EBCEF1 /* ColumnView.swift */; };
9656CD101C6BF28600EBCEF1 /* RowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9656CD0E1C6BF28600EBCEF1 /* RowView.swift */; };
966F57B81C226D75009185B7 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57B71C226D75009185B7 /* TextField.swift */; }; 966F57B81C226D75009185B7 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57B71C226D75009185B7 /* TextField.swift */; };
96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; }; 96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; };
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; }; 96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; };
...@@ -134,8 +132,6 @@ ...@@ -134,8 +132,6 @@
963832591B88E31A0015F710 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 963832591B88E31A0015F710 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
96442ADD1C28EF3700C3C574 /* MaterialTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTableViewCell.swift; sourceTree = "<group>"; }; 96442ADD1C28EF3700C3C574 /* MaterialTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTableViewCell.swift; sourceTree = "<group>"; };
9656CD0B1C6BD33700EBCEF1 /* Grid.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Grid.swift; sourceTree = "<group>"; }; 9656CD0B1C6BD33700EBCEF1 /* Grid.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Grid.swift; sourceTree = "<group>"; };
9656CD0D1C6BF28600EBCEF1 /* ColumnView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColumnView.swift; sourceTree = "<group>"; };
9656CD0E1C6BF28600EBCEF1 /* RowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowView.swift; sourceTree = "<group>"; };
966F57B71C226D75009185B7 /* TextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; }; 966F57B71C226D75009185B7 /* TextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; };
96D88BF51C1328D800B91418 /* CaptureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaptureView.swift; sourceTree = "<group>"; }; 96D88BF51C1328D800B91418 /* CaptureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaptureView.swift; sourceTree = "<group>"; };
96D88BF61C1328D800B91418 /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; }; 96D88BF61C1328D800B91418 /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; };
...@@ -236,8 +232,6 @@ ...@@ -236,8 +232,6 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
9656CD0B1C6BD33700EBCEF1 /* Grid.swift */, 9656CD0B1C6BD33700EBCEF1 /* Grid.swift */,
9656CD0E1C6BF28600EBCEF1 /* RowView.swift */,
9656CD0D1C6BF28600EBCEF1 /* ColumnView.swift */,
); );
name = Grid; name = Grid;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -609,14 +603,12 @@ ...@@ -609,14 +603,12 @@
96D88C361C1328D800B91418 /* MaterialPulseView.swift in Sources */, 96D88C361C1328D800B91418 /* MaterialPulseView.swift in Sources */,
960B23301C383EAA00E96216 /* Material+UIImage+Network.swift in Sources */, 960B23301C383EAA00E96216 /* Material+UIImage+Network.swift in Sources */,
96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */, 96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */,
9656CD101C6BF28600EBCEF1 /* RowView.swift in Sources */,
96D88C2D1C1328D800B91418 /* MaterialDepth.swift in Sources */, 96D88C2D1C1328D800B91418 /* MaterialDepth.swift in Sources */,
96D88C331C1328D800B91418 /* MaterialLabel.swift in Sources */, 96D88C331C1328D800B91418 /* MaterialLabel.swift in Sources */,
96D88C281C1328D800B91418 /* MaterialAnimation.swift in Sources */, 96D88C281C1328D800B91418 /* MaterialAnimation.swift in Sources */,
960B232E1C383EAA00E96216 /* Material+UIImage.swift in Sources */, 960B232E1C383EAA00E96216 /* Material+UIImage.swift in Sources */,
96D88C451C1328D800B91418 /* RobotoFont.swift in Sources */, 96D88C451C1328D800B91418 /* RobotoFont.swift in Sources */,
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */, 96D88C1F1C1328D800B91418 /* CardView.swift in Sources */,
9656CD0F1C6BF28600EBCEF1 /* ColumnView.swift in Sources */,
96D88C2C1C1328D800B91418 /* MaterialColor.swift in Sources */, 96D88C2C1C1328D800B91418 /* MaterialColor.swift in Sources */,
96D88C301C1328D800B91418 /* MaterialEdgeInsetPreset.swift in Sources */, 96D88C301C1328D800B91418 /* MaterialEdgeInsetPreset.swift in Sources */,
96D88C211C1328D800B91418 /* CaptureSession.swift in Sources */, 96D88C211C1328D800B91418 /* CaptureSession.swift in Sources */,
......
/*
* Copyright (C) 2015 - 20spacing, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
public class ColumnView : MaterialView {
// internal var grid: Grid
//
// public required init?(coder aDecoder: NSCoder) {
// grid = Grid()
// super.init(coder: aDecoder)
// }
//
// public override init(frame: CGRect) {
// grid = Grid()
// super.init(frame: frame)
// }
//
// public convenience init() {
// self.init(frame: CGRectNull)
// }
//
// public override func layoutSubviews() {
// super.layoutSubviews()
// grid.reloadLayout()
// }
}
\ No newline at end of file
...@@ -30,19 +30,19 @@ ...@@ -30,19 +30,19 @@
import UIKit import UIKit
public enum GridSize : Int { public enum Cell : Int {
case Grid1 = 1 case Cell1 = 1
case Grid2 = 2 case Cell2 = 2
case Grid3 = 3 case Cell3 = 3
case Grid4 = 4 case Cell4 = 4
case Grid5 = 5 case Cell5 = 5
case Grid6 = 6 case Cell6 = 6
case Grid7 = 7 case Cell7 = 7
case Grid8 = 8 case Cell8 = 8
case Grid9 = 9 case Cell9 = 9
case Grid10 = 10 case Cell10 = 10
case Grid11 = 11 case Cell11 = 11
case Grid12 = 12 case Cell12 = 12
} }
public enum GridLayout { public enum GridLayout {
...@@ -52,29 +52,22 @@ public enum GridLayout { ...@@ -52,29 +52,22 @@ public enum GridLayout {
public protocol GridCell { public protocol GridCell {
/// Grid column size. /// Grid column size.
var column: GridSize { get set } var column: Cell { get set }
/// Grid row size. /// Grid row size.
var row: GridSize { get set } var row: Cell { get set }
} }
public class Grid { public class Grid {
/// The size of the grid. /// The row size.
public var size: CGSize = CGSizeZero { public var row: Cell {
didSet { didSet {
reloadLayout() reloadLayout()
} }
} }
/// The column size. /// The column size.
public var column: GridSize { public var column: Cell {
didSet {
reloadLayout()
}
}
/// The row size.
public var row: GridSize {
didSet { didSet {
reloadLayout() reloadLayout()
} }
...@@ -115,7 +108,7 @@ public class Grid { ...@@ -115,7 +108,7 @@ public class Grid {
} }
} }
public init(row: GridSize = .Grid12, column: GridSize = .Grid12, spacing: CGFloat = 0) { public init(row: Cell = .Cell12, column: Cell = .Cell12, spacing: CGFloat = 0) {
self.row = row self.row = row
self.column = column self.column = column
self.spacing = spacing self.spacing = spacing
...@@ -123,36 +116,55 @@ public class Grid { ...@@ -123,36 +116,55 @@ public class Grid {
/// Reload the button layout. /// Reload the button layout.
public func reloadLayout() { public func reloadLayout() {
let gc: Int = column.rawValue
let gr: Int = row.rawValue
let w: CGFloat = (size.width - contentInset.left - contentInset.right) / CGFloat(gc)
let h: CGFloat = (size.height - contentInset.top - contentInset.bottom - spacing) / CGFloat(gr)
if let v: Array<UIView> = views { if let v: Array<UIView> = views {
var n: Int = 0 var n: Int = 0
var m: Int = 0 var m: Int = 0
for var i: Int = 0, l: Int = v.count - 1; i <= l; ++i { for var i: Int = 0, l: Int = v.count - 1; i <= l; ++i {
let view: UIView = v[i] let view: UIView = v[i]
let c: Int = view.grid.column.rawValue if let sv: UIView = view.superview {
let r: Int = view.grid.row.rawValue let w: CGFloat = (sv.bounds.width - contentInset.left - contentInset.right + spacing) / CGFloat(column.rawValue)
if .Horizontal == layout { let h: CGFloat = (sv.bounds.height - contentInset.top - contentInset.bottom + spacing) / CGFloat(row.rawValue)
if 0 == i { let c: Int = view.grid.column.rawValue
view.frame = CGRectMake(CGFloat(i + n) * w + contentInset.left, contentInset.top, (w * CGFloat(c)) - spacing, (0 < size.height ? size.height : view.intrinsicContentSize().height) - contentInset.top - contentInset.bottom) let r: Int = view.grid.row.rawValue
} else if l == i { if .Horizontal == layout {
view.frame = CGRectMake(CGFloat(i + n) * w + contentInset.left + spacing, contentInset.top, (w * CGFloat(c)) - spacing, (0 < size.height ? size.height : view.intrinsicContentSize().height) - contentInset.top - contentInset.bottom)
} else { // View height.
view.frame = CGRectMake(CGFloat(i + n) * w + contentInset.right, contentInset.top, (w * CGFloat(c)) - spacing, (0 < size.height ? size.height : view.intrinsicContentSize().height) - contentInset.top - contentInset.bottom) let vh: CGFloat = sv.bounds.height - contentInset.top - contentInset.bottom
}
} else { // View left.
if 0 == i { let vl: CGFloat = CGFloat(i + n) * w + contentInset.left
view.frame = CGRectMake(contentInset.left, CGFloat(i + m) * h + contentInset.top + spacing, (0 < size.width ? size.width : view.intrinsicContentSize().width) - contentInset.left - contentInset.right, (h * CGFloat(r)) - spacing)
} else if l == i { // View width.
view.frame = CGRectMake(contentInset.left, CGFloat(i + m) * h + contentInset.top + spacing, (0 < size.width ? size.width : view.intrinsicContentSize().width) - contentInset.left - contentInset.right, (h * CGFloat(r)) - spacing) let vw: CGFloat = (w * CGFloat(c)) - spacing
} else {
view.frame = CGRectMake(contentInset.left, CGFloat(i + m) * h + contentInset.top + spacing, (0 < size.width ? size.width : view.intrinsicContentSize().width) - contentInset.left - contentInset.right, (h * CGFloat(r)) - spacing) if 0 == i {
view.frame = CGRectMake(vl, contentInset.top, vw, vh)
} else if l == i {
view.frame = CGRectMake(vl, contentInset.top, vw, vh)
} else {
view.frame = CGRectMake(vl, contentInset.top, vw, vh)
}
} else if .Vertical == layout {
// View width.
let vw: CGFloat = sv.bounds.width - contentInset.left - contentInset.right
// View top.
let vt: CGFloat = CGFloat(i + m) * h + contentInset.top
// View height.
let vh: CGFloat = (h * CGFloat(r)) - spacing
if 0 == i {
view.frame = CGRectMake(contentInset.left, vt, vw, vh)
} else if l == i {
view.frame = CGRectMake(contentInset.left, vt, vw, vh)
} else {
view.frame = CGRectMake(contentInset.left, vt, vw, vh)
}
} }
n += c - 1
m += r - 1
} }
n += c - 1
m += r - 1
} }
} }
} }
......
/*
* Copyright (C) 2015 - 20spacing, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
public class RowView : MaterialView {
// internal var grid: Grid
//
// public required init?(coder aDecoder: NSCoder) {
// grid = Grid()
// super.init(coder: aDecoder)
// }
//
// public override init(frame: CGRect) {
// grid = Grid()
// super.init(frame: frame)
// }
//
// public convenience init() {
// self.init(frame: CGRectNull)
// }
//
// public override func layoutSubviews() {
// super.layoutSubviews()
// grid.reloadLayout()
// }
}
\ No newline at end of file
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