Commit 686c77a7 by Daniel Dahan

fixed issue-179 and issue-181

parent cf6e12ec
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Material' s.name = 'Material'
s.version = '1.34.5' s.version = '1.34.6'
s.license = 'BSD' s.license = 'BSD'
s.summary = 'Express your creativity with Material, an animation and graphics framework for Google\'s Material Design and Apple\'s Flat UI in Swift.' s.summary = 'Express your creativity with Material, an animation and graphics framework for Google\'s Material Design and Apple\'s Flat UI in Swift.'
s.homepage = 'http://cosmicmind.io' s.homepage = 'http://cosmicmind.io'
......
...@@ -57,12 +57,6 @@ ...@@ -57,12 +57,6 @@
96CC08381C7CCB7C0034FF84 /* NavigationBarViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96A71F2F1C72E41100C0C4AE /* NavigationBarViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96CC08381C7CCB7C0034FF84 /* NavigationBarViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96A71F2F1C72E41100C0C4AE /* NavigationBarViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96CC083D1C7CF9D40034FF84 /* StatusBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */; }; 96CC083D1C7CF9D40034FF84 /* StatusBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */; };
96CC083E1C7CFF2A0034FF84 /* StatusBarViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96CC083E1C7CFF2A0034FF84 /* StatusBarViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96CC08511C7D7BB00034FF84 /* MaterialCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC08501C7D7BB00034FF84 /* MaterialCollectionViewCell.swift */; };
96CC08551C7D7C8C0034FF84 /* MaterialCollectionViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC08541C7D7C8C0034FF84 /* MaterialCollectionViewLayout.swift */; };
96CC08581C7E11430034FF84 /* MaterialCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC08571C7E11430034FF84 /* MaterialCollectionView.swift */; };
96CC085A1C7E16BD0034FF84 /* MaterialCollectionViewDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC08591C7E16BD0034FF84 /* MaterialCollectionViewDataSource.swift */; };
96CC085C1C7E16F20034FF84 /* MaterialCollectionViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC085B1C7E16F20034FF84 /* MaterialCollectionViewDelegate.swift */; };
96CC085E1C7E1D550034FF84 /* MaterialDataSourceItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC085D1C7E1D550034FF84 /* MaterialDataSourceItem.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 */; };
96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */; }; 96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */; };
...@@ -170,12 +164,6 @@ ...@@ -170,12 +164,6 @@
96A71FB01C7649F800C0C4AE /* ControlView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControlView.swift; sourceTree = "<group>"; }; 96A71FB01C7649F800C0C4AE /* ControlView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControlView.swift; sourceTree = "<group>"; };
96A71FB21C764E3200C0C4AE /* StatusBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarView.swift; sourceTree = "<group>"; }; 96A71FB21C764E3200C0C4AE /* StatusBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarView.swift; sourceTree = "<group>"; };
96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarViewController.swift; sourceTree = "<group>"; }; 96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarViewController.swift; sourceTree = "<group>"; };
96CC08501C7D7BB00034FF84 /* MaterialCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionViewCell.swift; sourceTree = "<group>"; };
96CC08541C7D7C8C0034FF84 /* MaterialCollectionViewLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionViewLayout.swift; sourceTree = "<group>"; };
96CC08571C7E11430034FF84 /* MaterialCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionView.swift; sourceTree = "<group>"; };
96CC08591C7E16BD0034FF84 /* MaterialCollectionViewDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionViewDataSource.swift; sourceTree = "<group>"; };
96CC085B1C7E16F20034FF84 /* MaterialCollectionViewDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionViewDelegate.swift; sourceTree = "<group>"; };
96CC085D1C7E1D550034FF84 /* MaterialDataSourceItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialDataSourceItem.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>"; };
96D88BF71C1328D800B91418 /* CapturePreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreviewView.swift; sourceTree = "<group>"; }; 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreviewView.swift; sourceTree = "<group>"; };
...@@ -333,19 +321,6 @@ ...@@ -333,19 +321,6 @@
name = Switch; name = Switch;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
96CC084F1C7D7B9B0034FF84 /* CollectionView */ = {
isa = PBXGroup;
children = (
96CC08501C7D7BB00034FF84 /* MaterialCollectionViewCell.swift */,
96CC08541C7D7C8C0034FF84 /* MaterialCollectionViewLayout.swift */,
96CC08571C7E11430034FF84 /* MaterialCollectionView.swift */,
96CC08591C7E16BD0034FF84 /* MaterialCollectionViewDataSource.swift */,
96CC085B1C7E16F20034FF84 /* MaterialCollectionViewDelegate.swift */,
96CC085D1C7E1D550034FF84 /* MaterialDataSourceItem.swift */,
);
name = CollectionView;
sourceTree = "<group>";
};
96CC08561C7E0EC00034FF84 /* ControlView */ = { 96CC08561C7E0EC00034FF84 /* ControlView */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -373,7 +348,6 @@ ...@@ -373,7 +348,6 @@
96D88C471C1328F500B91418 /* Font */, 96D88C471C1328F500B91418 /* Font */,
966F57B61C226D65009185B7 /* Text */, 966F57B61C226D65009185B7 /* Text */,
96442ADC1C28EF1400C3C574 /* TableView */, 96442ADC1C28EF1400C3C574 /* TableView */,
96CC084F1C7D7B9B0034FF84 /* CollectionView */,
965C58BD1C6B8D3300CFB4E1 /* Grid */, 965C58BD1C6B8D3300CFB4E1 /* Grid */,
96A71E921C6FBC2900C0C4AE /* Menu */, 96A71E921C6FBC2900C0C4AE /* Menu */,
96A71EC51C6FFEF300C0C4AE /* Switch */, 96A71EC51C6FFEF300C0C4AE /* Switch */,
...@@ -706,24 +680,20 @@ ...@@ -706,24 +680,20 @@
960036151C77E1B600EBA579 /* SearchBarViewController.swift in Sources */, 960036151C77E1B600EBA579 /* SearchBarViewController.swift in Sources */,
96A71EF61C71127100C0C4AE /* SearchBarView.swift in Sources */, 96A71EF61C71127100C0C4AE /* SearchBarView.swift in Sources */,
96D88C371C1328D800B91418 /* MaterialRadius.swift in Sources */, 96D88C371C1328D800B91418 /* MaterialRadius.swift in Sources */,
96CC08581C7E11430034FF84 /* MaterialCollectionView.swift in Sources */,
960B232F1C383EAA00E96216 /* Material+UIImage+Crop.swift in Sources */, 960B232F1C383EAA00E96216 /* Material+UIImage+Crop.swift in Sources */,
96D88C241C1328D800B91418 /* ImageCardView.swift in Sources */, 96D88C241C1328D800B91418 /* ImageCardView.swift in Sources */,
96D88C2B1C1328D800B91418 /* MaterialButton.swift in Sources */, 96D88C2B1C1328D800B91418 /* MaterialButton.swift in Sources */,
96D88C311C1328D800B91418 /* MaterialKeyframeAnimation.swift in Sources */, 96D88C311C1328D800B91418 /* MaterialKeyframeAnimation.swift in Sources */,
96D88C2E1C1328D800B91418 /* MaterialFont.swift in Sources */, 96D88C2E1C1328D800B91418 /* MaterialFont.swift in Sources */,
9656CD0C1C6BD33700EBCEF1 /* Grid.swift in Sources */, 9656CD0C1C6BD33700EBCEF1 /* Grid.swift in Sources */,
96CC08551C7D7C8C0034FF84 /* MaterialCollectionViewLayout.swift in Sources */,
96A71FB31C764E3200C0C4AE /* StatusBarView.swift in Sources */, 96A71FB31C764E3200C0C4AE /* StatusBarView.swift in Sources */,
960B23461C38480E00E96216 /* Text.swift in Sources */, 960B23461C38480E00E96216 /* Text.swift in Sources */,
96D88C351C1328D800B91418 /* MaterialLayout.swift in Sources */, 96D88C351C1328D800B91418 /* MaterialLayout.swift in Sources */,
96D88C2F1C1328D800B91418 /* MaterialGravity.swift in Sources */, 96D88C2F1C1328D800B91418 /* MaterialGravity.swift in Sources */,
96D88C231C1328D800B91418 /* FlatButton.swift in Sources */, 96D88C231C1328D800B91418 /* FlatButton.swift in Sources */,
96CC08511C7D7BB00034FF84 /* MaterialCollectionViewCell.swift in Sources */,
966F57B81C226D75009185B7 /* TextField.swift in Sources */, 966F57B81C226D75009185B7 /* TextField.swift in Sources */,
96DBA7361C61198400844821 /* Material+UIImage+Color.swift in Sources */, 96DBA7361C61198400844821 /* Material+UIImage+Color.swift in Sources */,
96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */, 96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */,
96CC085C1C7E16F20034FF84 /* MaterialCollectionViewDelegate.swift in Sources */,
96A71EC71C6FFF0500C0C4AE /* MaterialSwitch.swift in Sources */, 96A71EC71C6FFF0500C0C4AE /* MaterialSwitch.swift in Sources */,
96D88C3E1C1328D800B91418 /* NavigationBarView.swift in Sources */, 96D88C3E1C1328D800B91418 /* NavigationBarView.swift in Sources */,
96D88C221C1328D800B91418 /* FabButton.swift in Sources */, 96D88C221C1328D800B91418 /* FabButton.swift in Sources */,
...@@ -739,7 +709,6 @@ ...@@ -739,7 +709,6 @@
96D88C331C1328D800B91418 /* MaterialLabel.swift in Sources */, 96D88C331C1328D800B91418 /* MaterialLabel.swift in Sources */,
96D88C281C1328D800B91418 /* MaterialAnimation.swift in Sources */, 96D88C281C1328D800B91418 /* MaterialAnimation.swift in Sources */,
96A71F301C72E41100C0C4AE /* NavigationBarViewController.swift in Sources */, 96A71F301C72E41100C0C4AE /* NavigationBarViewController.swift in Sources */,
96CC085E1C7E1D550034FF84 /* MaterialDataSourceItem.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 */,
...@@ -757,7 +726,6 @@ ...@@ -757,7 +726,6 @@
9626C2DE1C795017007CA8E0 /* MenuViewController.swift in Sources */, 9626C2DE1C795017007CA8E0 /* MenuViewController.swift in Sources */,
96A71FB61C7651AA00C0C4AE /* ControlView.swift in Sources */, 96A71FB61C7651AA00C0C4AE /* ControlView.swift in Sources */,
96A71F451C74ABCB00C0C4AE /* MaterialBorder.swift in Sources */, 96A71F451C74ABCB00C0C4AE /* MaterialBorder.swift in Sources */,
96CC085A1C7E16BD0034FF84 /* MaterialCollectionViewDataSource.swift in Sources */,
96A71E911C6FBC2200C0C4AE /* MenuView.swift in Sources */, 96A71E911C6FBC2200C0C4AE /* MenuView.swift in Sources */,
96D88C271C1328D800B91418 /* Material+UIFont.swift in Sources */, 96D88C271C1328D800B91418 /* Material+UIFont.swift in Sources */,
); );
......
...@@ -129,48 +129,48 @@ public class ControlView : MaterialView { ...@@ -129,48 +129,48 @@ public class ControlView : MaterialView {
} }
// Size of single grid column. // Size of single grid column.
let g: CGFloat = width / CGFloat(0 < grid.axis.columns ? grid.axis.columns : 1) if let g: CGFloat = width / CGFloat(0 < grid.axis.columns ? grid.axis.columns : 1) {
grid.views = []
grid.views = [] contentView.grid.columns = grid.axis.columns
contentView.grid.columns = grid.axis.columns
// leftControls
// leftControls if let v: Array<UIControl> = leftControls {
if let v: Array<UIControl> = leftControls { for c in v {
for c in v { let w: CGFloat = c.intrinsicContentSize().width
let w: CGFloat = c.intrinsicContentSize().width if let b: UIButton = c as? UIButton {
if let b: UIButton = c as? UIButton { b.contentEdgeInsets = UIEdgeInsetsZero
b.contentEdgeInsets = UIEdgeInsetsZero }
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views?.append(c)
} }
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views?.append(c)
} }
}
grid.views?.append(contentView)
grid.views?.append(contentView)
// rightControls
// rightControls if let v: Array<UIControl> = rightControls {
if let v: Array<UIControl> = rightControls { for c in v {
for c in v { let w: CGFloat = c.intrinsicContentSize().width
let w: CGFloat = c.intrinsicContentSize().width if let b: UIButton = c as? UIButton {
if let b: UIButton = c as? UIButton { b.contentEdgeInsets = UIEdgeInsetsZero
b.contentEdgeInsets = UIEdgeInsetsZero }
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views?.append(c)
} }
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views?.append(c)
} }
contentView.grid.columns -= contentView.grid.offset.columns
grid.reloadLayout()
} }
contentView.grid.columns -= contentView.grid.offset.columns
grid.reloadLayout()
} }
/** /**
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.34.5</string> <string>1.34.6</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
/*
* Copyright (C) 2015 - 2016, 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 MaterialCollectionView : UICollectionView {
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
/**
An initializer that initializes the object.
- Parameter frame: A CGRect defining the view's frame.
- Parameter collectionViewLayout: A UICollectionViewLayout reference.
*/
public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
prepareView()
}
/**
An initializer that initializes the object.
- Parameter frame: A CGRect defining the view's frame.
*/
public init(frame: CGRect) {
super.init(frame: frame, collectionViewLayout: MaterialCollectionViewLayout())
prepareView()
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public func prepareView() {
backgroundColor = MaterialColor.clear
contentInset = UIEdgeInsetsZero
}
}
/*
* Copyright (C) 2015 - 2016, 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.
*/
public protocol MaterialCollectionViewDataSource : MaterialDelegate, UICollectionViewDataSource {
/**
/// Retrieves the items for the collectionView.
- Returns: An Array of Arrays of MaterialDataSourceItem objects.
*/
func items() -> Array<Array<MaterialDataSourceItem>>
}
\ No newline at end of file
/*
* Copyright (C) 2015 - 2016, 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.
*/
public protocol MaterialCollectionViewDelegate : MaterialDelegate, UICollectionViewDelegate {
}
\ No newline at end of file
/*
* Copyright (C) 2015 - 2016, 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 MaterialCollectionViewLayout : UICollectionViewLayout {
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset = .None {
didSet {
contentInset = MaterialEdgeInsetToValue(contentInsetPreset)
}
}
/// A wrapper around grid.contentInset.
public var contentInset: UIEdgeInsets = UIEdgeInsetsZero
/// Size of the content.
private var contentSize: CGSize = CGSizeZero
/// Layout attribute items.
private var layoutItems: Array<(UICollectionViewLayoutAttributes, NSIndexPath)> = Array<(UICollectionViewLayoutAttributes, NSIndexPath)>()
/// Used to calculate the dimensions of the cells.
private var offset: CGPoint = CGPointZero
/// Cell items.
private var items: Array<Array<MaterialDataSourceItem>>?
/// Scroll direction.
public var scrollDirection: UICollectionViewScrollDirection = .Vertical
/// Scale of the screen.
public var scale: CGFloat = 2
/// Spacing between items.
public var spacing: CGFloat = 0
/**
Retrieves the index paths for the items within the passed in CGRect.
- Parameter rect: A CGRect that acts as the bounds to find the items within.
- Returns: An Array of NSIndexPath objects.
*/
public func indexPathsOfItemsInRect(rect: CGRect) -> Array<NSIndexPath> {
var paths: Array<NSIndexPath> = Array<NSIndexPath>()
for (attribute, indexPath) in layoutItems {
if CGRectIntersectsRect(rect, attribute.frame) {
paths.append(indexPath)
}
}
return paths
}
public override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attributes: UICollectionViewLayoutAttributes = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath)
let item: MaterialDataSourceItem = items![indexPath.section][indexPath.item]
switch scrollDirection {
case .Vertical:
attributes.frame = CGRectMake(contentInset.left, offset.y, collectionView!.bounds.width - contentInset.left - contentInset.right, nil == item.size?.height ? collectionView!.bounds.height : item.size!.height)
case .Horizontal:
attributes.frame = CGRectMake(offset.x, contentInset.top, nil == item.size?.width ? collectionView!.bounds.width : item.size!.width, collectionView!.bounds.height - contentInset.top - contentInset.bottom)
}
return attributes
}
public override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var layoutAttributes: Array<UICollectionViewLayoutAttributes> = Array<UICollectionViewLayoutAttributes>()
for (attribute, _) in layoutItems {
if CGRectIntersectsRect(rect, attribute.frame) {
layoutAttributes.append(attribute)
}
}
return layoutAttributes
}
public override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool {
return .Vertical == scrollDirection ? newBounds.width != collectionView!.bounds.width : newBounds.height != collectionView!.bounds.height
}
public override func collectionViewContentSize() -> CGSize {
return contentSize
}
public override func prepareLayout() {
let dataSource: MaterialCollectionViewDataSource = collectionView!.dataSource as! MaterialCollectionViewDataSource
items = dataSource.items()
layoutItems.removeAll()
offset.x = contentInset.left
offset.y = contentInset.top
var indexPath: NSIndexPath?
for var i: Int = 0, l: Int = items!.count - 1; i <= l; ++i {
let v: Array<MaterialDataSourceItem> = items![i]
for var j: Int = 0, k: Int = v.count - 1; j <= k; ++j {
let item: MaterialDataSourceItem = v[j]
indexPath = NSIndexPath(forItem: j, inSection: i)
layoutItems.append((layoutAttributesForItemAtIndexPath(indexPath!)!, indexPath!))
offset.x += spacing
offset.x += nil == item.size?.width ? 0 : item.size!.width
offset.y += spacing
offset.y += nil == item.size?.height ? 0 : item.size!.height
}
}
offset.x += contentInset.right - spacing
offset.y += contentInset.bottom - spacing
contentSize = .Vertical == scrollDirection ? CGSizeMake(collectionView!.bounds.width, offset.y) : CGSizeMake(offset.x, collectionView!.bounds.height)
}
public override func targetContentOffsetForProposedContentOffset(proposedContentOffset: CGPoint) -> CGPoint {
return proposedContentOffset
}
}
/*
* Copyright (C) 2015 - 2016, 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.
*/
public struct MaterialDataSourceItem {
public var data: AnyObject?
public var size: CGSize?
public var origin: CGPoint?
public init(data: AnyObject? = nil, size: CGSize? = nil, origin: CGPoint? = nil) {
self.data = data
self.size = size
self.origin = origin
}
}
\ No newline at end of file
...@@ -173,7 +173,7 @@ public class MaterialSwitch: UIControl { ...@@ -173,7 +173,7 @@ public class MaterialSwitch: UIControl {
return .On == internalSwitchState return .On == internalSwitchState
} }
set(value) { set(value) {
setOn(selected, animated: true) setOn(value, animated: true)
} }
} }
...@@ -182,7 +182,17 @@ public class MaterialSwitch: UIControl { ...@@ -182,7 +182,17 @@ public class MaterialSwitch: UIControl {
return .On == internalSwitchState return .On == internalSwitchState
} }
set(value) { set(value) {
setOn(highlighted, animated: true) setOn(value, animated: true)
}
}
/// A boolean indicating if the switch is on or not.
public var on: Bool {
get {
return .On == internalSwitchState
}
set(value) {
setOn(value, animated: true)
} }
} }
...@@ -205,16 +215,6 @@ public class MaterialSwitch: UIControl { ...@@ -205,16 +215,6 @@ public class MaterialSwitch: UIControl {
} }
} }
/// A boolean indicating if the switch is on or not.
public var on: Bool {
get {
return .On == internalSwitchState
}
set(value) {
setOn(on, animated: true)
}
}
/// MaterialSwitch style. /// MaterialSwitch style.
public var switchStyle: MaterialSwitchStyle = .Default { public var switchStyle: MaterialSwitchStyle = .Default {
didSet { didSet {
...@@ -348,7 +348,7 @@ public class MaterialSwitch: UIControl { ...@@ -348,7 +348,7 @@ public class MaterialSwitch: UIControl {
- Parameter animated: A Boolean indicating to set the animation or not. - Parameter animated: A Boolean indicating to set the animation or not.
*/ */
public func setOn(on: Bool, animated: Bool, completion: ((control: MaterialSwitch) -> Void)? = nil) { public func setOn(on: Bool, animated: Bool, completion: ((control: MaterialSwitch) -> Void)? = nil) {
setSwitchState(on == true ? .On : .Off, animated: animated, completion: completion) setSwitchState(on ? .On : .Off, animated: animated, completion: completion)
} }
/** /**
......
...@@ -71,6 +71,8 @@ public class NavigationBarView : StatusBarView { ...@@ -71,6 +71,8 @@ public class NavigationBarView : StatusBarView {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
width = UIScreen.mainScreen().bounds.width
grid.axis.columns = Int(width / 48) grid.axis.columns = Int(width / 48)
// TitleView alignment. // TitleView alignment.
...@@ -91,7 +93,7 @@ public class NavigationBarView : StatusBarView { ...@@ -91,7 +93,7 @@ public class NavigationBarView : StatusBarView {
contentView.grid.contentInset.top = 0 contentView.grid.contentInset.top = 0
} }
} }
reloadView() reloadView()
} }
...@@ -121,6 +123,11 @@ public class NavigationBarView : StatusBarView { ...@@ -121,6 +123,11 @@ public class NavigationBarView : StatusBarView {
contentView.grid.axis.direction = .Vertical contentView.grid.axis.direction = .Vertical
} }
/// Called when the NavigationBarView changes size.
public override func statusBarViewDidChangeLayout() {
(delegate as? NavigationBarViewDelegate)?.navigationBarViewDidChangeLayout?(self)
}
/** /**
Used to trigger property changes that initializers avoid. Used to trigger property changes that initializers avoid.
- Parameter titleLabel: UILabel for the title. - Parameter titleLabel: UILabel for the title.
...@@ -133,8 +140,4 @@ public class NavigationBarView : StatusBarView { ...@@ -133,8 +140,4 @@ public class NavigationBarView : StatusBarView {
self.titleLabel = titleLabel self.titleLabel = titleLabel
self.detailLabel = detailLabel self.detailLabel = detailLabel
} }
internal override func statusBarViewDidChangeLayout() {
(delegate as? NavigationBarViewDelegate)?.navigationBarViewDidChangeLayout?(self)
}
} }
...@@ -120,6 +120,11 @@ public class SearchBarView : StatusBarView { ...@@ -120,6 +120,11 @@ public class SearchBarView : StatusBarView {
prepareTextField() prepareTextField()
} }
/// Called when the SearchBarView changes size.
public override func statusBarViewDidChangeLayout() {
(delegate as? SearchBarViewDelegate)?.searchBarViewDidChangeLayout?(self)
}
/// Prepares the textField. /// Prepares the textField.
private func prepareTextField() { private func prepareTextField() {
textField.placeholder = "Search" textField.placeholder = "Search"
...@@ -128,8 +133,4 @@ public class SearchBarView : StatusBarView { ...@@ -128,8 +133,4 @@ public class SearchBarView : StatusBarView {
contentView.addSubview(textField) contentView.addSubview(textField)
contentView.grid.views = [textField] contentView.grid.views = [textField]
} }
internal override func statusBarViewDidChangeLayout() {
(delegate as? SearchBarViewDelegate)?.searchBarViewDidChangeLayout?(self)
}
} }
...@@ -58,6 +58,9 @@ public class StatusBarView : ControlView { ...@@ -58,6 +58,9 @@ public class StatusBarView : ControlView {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
width = UIScreen.mainScreen().bounds.width
// General alignment. // General alignment.
if UIApplication.sharedApplication().statusBarOrientation.isLandscape { if UIApplication.sharedApplication().statusBarOrientation.isLandscape {
grid.contentInset.top = 8 grid.contentInset.top = 8
...@@ -67,15 +70,11 @@ public class StatusBarView : ControlView { ...@@ -67,15 +70,11 @@ public class StatusBarView : ControlView {
height = 64 height = 64
} }
width = UIScreen.mainScreen().bounds.width
reloadView()
if frame.origin.x != oldFrame!.origin.x || frame.origin.y != oldFrame!.origin.y || frame.width != oldFrame!.width || frame.height != oldFrame!.height { if frame.origin.x != oldFrame!.origin.x || frame.origin.y != oldFrame!.origin.y || frame.width != oldFrame!.width || frame.height != oldFrame!.height {
oldFrame = frame
if nil != delegate { if nil != delegate {
statusBarViewDidChangeLayout() statusBarViewDidChangeLayout()
} }
oldFrame = frame
} }
} }
...@@ -106,5 +105,5 @@ public class StatusBarView : ControlView { ...@@ -106,5 +105,5 @@ public class StatusBarView : ControlView {
} }
/// Chaining method for subclasses to offer delegation or other useful features. /// Chaining method for subclasses to offer delegation or other useful features.
internal func statusBarViewDidChangeLayout() {} public func statusBarViewDidChangeLayout() {}
} }
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