Commit db8f6f19 by Daniel Dahan

initial SearchBarView, MaterialTextView, and icons

parent ca6e49e9
......@@ -45,6 +45,7 @@
962F3E541BACA7FB0004B8AD /* NavigationBarView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 962F3E521BACA68C0004B8AD /* NavigationBarView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
963832421B88DFD80015F710 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* MaterialKit.framework */; };
9638325A1B88E31A0015F710 /* MaterialKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963832581B88E31A0015F710 /* MaterialKitTests.swift */; };
963C7A6A1BD4729600D175C5 /* MaterialTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963C7A691BD4729600D175C5 /* MaterialTextView.swift */; settings = {ASSET_TAGS = (); }; };
964B17B41BBA447F002A9CA0 /* MaterialLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 964B17B31BBA447F002A9CA0 /* MaterialLayout.swift */; settings = {ASSET_TAGS = (); }; };
964B17B61BBA4BEA002A9CA0 /* MaterialStatusBarStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 964B17B51BBA4BEA002A9CA0 /* MaterialStatusBarStyle.swift */; settings = {ASSET_TAGS = (); }; };
964B17CC1BBB31C2002A9CA0 /* MaterialBorder.swift in Headers */ = {isa = PBXBuildFile; fileRef = 65BDD1691BB7146B006F7F2B /* MaterialBorder.swift */; settings = {ATTRIBUTES = (Public, ); }; };
......@@ -59,6 +60,13 @@
965C17C81BC82FEF00B1059A /* MaterialLayer.swift in Headers */ = {isa = PBXBuildFile; fileRef = 65AD15E91BC05B3A0068AF9C /* MaterialLayer.swift */; settings = {ATTRIBUTES = (Public, ); }; };
965C17C91BC82FEF00B1059A /* MaterialTextLayer.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */; settings = {ATTRIBUTES = (Public, ); }; };
965C17CA1BC82FEF00B1059A /* ImageCardView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96D26BFC1BC23649006478BD /* ImageCardView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9688D06D1BD4587200A70097 /* SearchBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9688D06C1BD4587200A70097 /* SearchBarView.swift */; settings = {ASSET_TAGS = (); }; };
9688D06F1BD45A5800A70097 /* Icons.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9688D06E1BD45A5800A70097 /* Icons.xcassets */; settings = {ASSET_TAGS = (); }; };
9688D0701BD45B8C00A70097 /* SideNavigationViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9693BF981BCDC1450087054A /* SideNavigationViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9688D0711BD45B8C00A70097 /* SearchBarView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9688D06C1BD4587200A70097 /* SearchBarView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9688D0721BD45B8C00A70097 /* MaterialPulseCollectionViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9693BF9F1BCF36A40087054A /* MaterialPulseCollectionViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9688D0731BD45B8C00A70097 /* MaterialPanCollectionViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9693BF9B1BCDC16C0087054A /* MaterialPanCollectionViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9688D0741BD45B8C00A70097 /* BasicCollectionViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9693BF9D1BCDC1840087054A /* BasicCollectionViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9693BF861BCB0E0A0087054A /* Material+UIFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9693BF851BCB0E0A0087054A /* Material+UIFont.swift */; settings = {ASSET_TAGS = (); }; };
9693BF8B1BCB35910087054A /* Material+UIFont.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9693BF851BCB0E0A0087054A /* Material+UIFont.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9693BF8D1BCB35910087054A /* MaterialBasicAnimation.swift in Headers */ = {isa = PBXBuildFile; fileRef = 65D2BEC61BBED1E400800B7B /* MaterialBasicAnimation.swift */; settings = {ATTRIBUTES = (Public, ); }; };
......@@ -120,8 +128,11 @@
963832581B88E31A0015F710 /* MaterialKitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialKitTests.swift; sourceTree = "<group>"; };
963832591B88E31A0015F710 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
963832631B88E5BF0015F710 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
963C7A691BD4729600D175C5 /* MaterialTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTextView.swift; sourceTree = "<group>"; };
964B17B31BBA447F002A9CA0 /* MaterialLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialLayout.swift; sourceTree = "<group>"; };
964B17B51BBA4BEA002A9CA0 /* MaterialStatusBarStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialStatusBarStyle.swift; sourceTree = "<group>"; };
9688D06C1BD4587200A70097 /* SearchBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchBarView.swift; sourceTree = "<group>"; };
9688D06E1BD45A5800A70097 /* Icons.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Icons.xcassets; sourceTree = "<group>"; };
9693BF851BCB0E0A0087054A /* Material+UIFont.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIFont.swift"; sourceTree = "<group>"; };
9693BF951BCCCB520087054A /* BasicCardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCardView.swift; sourceTree = "<group>"; };
9693BF981BCDC1450087054A /* SideNavigationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideNavigationViewController.swift; sourceTree = "<group>"; };
......@@ -238,13 +249,16 @@
isa = PBXGroup;
children = (
963832631B88E5BF0015F710 /* LICENSE */,
9688D06E1BD45A5800A70097 /* Icons.xcassets */,
9638325C1B88E3420015F710 /* Supporting Files */,
9693BF841BCB0DEE0087054A /* Extensions */,
96B57D4C1B90AF6A00DE7BBB /* Theme */,
9AAC38521B89553800FE6B2D /* Font */,
963C7A681BD4726900D175C5 /* Text */,
65AD15E81BC05B0E0068AF9C /* Layer */,
65B965851B8BEEB00055B139 /* View */,
965C17C21BC7258100B1059A /* Navigation */,
9688D06B1BD4585800A70097 /* Search */,
65BDD1551BB6FC60006F7F2B /* Button */,
65BDD1701BB8CD56006F7F2B /* Label */,
964B17D71BBB38E2002A9CA0 /* Card */,
......@@ -280,6 +294,14 @@
name = "Supporting Files";
sourceTree = "<group>";
};
963C7A681BD4726900D175C5 /* Text */ = {
isa = PBXGroup;
children = (
963C7A691BD4729600D175C5 /* MaterialTextView.swift */,
);
name = Text;
sourceTree = "<group>";
};
964B17B21BBA445D002A9CA0 /* Layout */ = {
isa = PBXGroup;
children = (
......@@ -306,6 +328,14 @@
name = Navigation;
sourceTree = "<group>";
};
9688D06B1BD4585800A70097 /* Search */ = {
isa = PBXGroup;
children = (
9688D06C1BD4587200A70097 /* SearchBarView.swift */,
);
name = Search;
sourceTree = "<group>";
};
9693BF841BCB0DEE0087054A /* Extensions */ = {
isa = PBXGroup;
children = (
......@@ -385,6 +415,11 @@
9693BF8D1BCB35910087054A /* MaterialBasicAnimation.swift in Headers */,
9693BF8E1BCB35910087054A /* MaterialKeyframeAnimation.swift in Headers */,
9693BF8F1BCB35910087054A /* MaterialTransitionAnimation.swift in Headers */,
9688D0701BD45B8C00A70097 /* SideNavigationViewController.swift in Headers */,
9688D0711BD45B8C00A70097 /* SearchBarView.swift in Headers */,
9688D0721BD45B8C00A70097 /* MaterialPulseCollectionViewCell.swift in Headers */,
9688D0731BD45B8C00A70097 /* MaterialPanCollectionViewCell.swift in Headers */,
9688D0741BD45B8C00A70097 /* BasicCollectionViewCell.swift in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -471,6 +506,7 @@
files = (
9A94D0FA1B895EA500F586A5 /* LICENSE in Resources */,
9A94D0FB1B895EA500F586A5 /* Roboto-Regular.ttf in Resources */,
9688D06F1BD45A5800A70097 /* Icons.xcassets in Resources */,
65DBE4211B9A9244000C804F /* Roboto-Thin.ttf in Resources */,
65DBE4201B9A9244000C804F /* Roboto-Bold.ttf in Resources */,
9A94D0FC1B895EA500F586A5 /* Roboto-Medium.ttf in Resources */,
......@@ -492,12 +528,14 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
963C7A6A1BD4729600D175C5 /* MaterialTextView.swift in Sources */,
65BDD15D1BB70D60006F7F2B /* MaterialInsets.swift in Sources */,
9693BF9E1BCDC1840087054A /* BasicCollectionViewCell.swift in Sources */,
65BDD1471BB5B916006F7F2B /* MaterialView.swift in Sources */,
65BDD16C1BB88D1A006F7F2B /* MaterialShape.swift in Sources */,
65AD15EA1BC05B3A0068AF9C /* MaterialLayer.swift in Sources */,
65BDD1521BB6EE7C006F7F2B /* RobotoFont.swift in Sources */,
9688D06D1BD4587200A70097 /* SearchBarView.swift in Sources */,
9693BF991BCDC1450087054A /* SideNavigationViewController.swift in Sources */,
9693BF961BCCCB520087054A /* BasicCardView.swift in Sources */,
96D26BFD1BC23649006478BD /* ImageCardView.swift in Sources */,
......
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_search_blue_grey_darken_4.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_search_blue_grey_darken_4@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_search_blue_grey_darken_4@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_search_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_search_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_search_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
import UIKit
public protocol MaterialTextViewDelegate : UITextViewDelegate {}
public class MaterialTextView: UITextView {
//
// :name: layoutConstraints
//
internal lazy var layoutConstraints: Array<NSLayoutConstraint> = Array<NSLayoutConstraint>()
/**
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
:name: init
*/
public override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
prepareView()
}
//
// :name: deinit
//
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidChangeNotification, object: nil)
}
/**
:name: placeholder
*/
public var placeholderLabel: UILabel? {
didSet {
if let p = placeholderLabel {
p.translatesAutoresizingMaskIntoConstraints = false
p.font = font
p.textAlignment = textAlignment
p.numberOfLines = 0
p.backgroundColor = .clearColor()
addSubview(p)
updateLabelConstraints()
textViewTextDidChange()
}
}
}
/**
:name: text
*/
public override var text: String! {
didSet {
textViewTextDidChange()
}
}
/**
:name: attributedText
*/
public override var attributedText: NSAttributedString! {
didSet {
textViewTextDidChange()
}
}
/**
:name: textContainerInset
*/
public override var textContainerInset: UIEdgeInsets {
didSet {
updateLabelConstraints()
}
}
public override func layoutSubviews() {
super.layoutSubviews()
placeholderLabel?.preferredMaxLayoutWidth = textContainer.size.width - textContainer.lineFragmentPadding * 2
}
/**
:name: updateLabelConstraints
*/
internal func updateLabelConstraints() {
if let p = placeholderLabel {
NSLayoutConstraint.deactivateConstraints(layoutConstraints)
layoutConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:|-(left)-[placeholderLabel]-(right)-|",
options: [],
metrics: [
"left": textContainerInset.left + textContainer.lineFragmentPadding,
"right": textContainerInset.right + textContainer.lineFragmentPadding
], views: [
"placeholderLabel": p
])
layoutConstraints += NSLayoutConstraint.constraintsWithVisualFormat("V:|-(top)-[placeholderLabel]-(>=bottom)-|",
options: [],
metrics: [
"top": textContainerInset.top,
"bottom": textContainerInset.bottom
],
views: [
"placeholderLabel": p
])
NSLayoutConstraint.activateConstraints(layoutConstraints)
}
}
//
// :name: textViewTextDidChange
//
internal func textViewTextDidChange() {
if let p = placeholderLabel {
p.hidden = !text.isEmpty
}
}
//
// :name: prepareView
//
private func prepareView() {
// label needs to be added to the view
// hierarchy before setting insets
textContainerInset = UIEdgeInsetsMake(16, 16, 16, 16)
backgroundColor = .clearColor()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "textViewTextDidChange", name: UITextViewTextDidChangeNotification, object: nil)
updateLabelConstraints()
}
}
......@@ -24,6 +24,7 @@ public struct MaterialTheme {
public struct basicCardView {}
public struct imageCardView {}
public struct navigationBarView {}
public struct searchBarView {}
public struct pulseCollectionView {}
public struct textLayer {}
public struct label {}
......@@ -205,6 +206,44 @@ public extension MaterialTheme.navigationBarView {
public static var zPosition: CGFloat = 100
}
// searchBarView
public extension MaterialTheme.searchBarView {
// frame
public static var x: CGFloat = 0
public static var y: CGFloat = 0
public static var width: CGFloat = UIScreen.mainScreen().bounds.width
public static var height: CGFloat = 70
// shadow
public static var shadowDepth: MaterialDepth = .Depth2
public static var shadowColor: UIColor = MaterialColor.black
// shape
public static var contentInsetsRef: MaterialInsetsType = MaterialInsetsToValue(.Square2)
public static var textFieldInsetsRef: MaterialInsetsType = (top: 20, left: 0, bottom: 0, right: 0)
public static var leftButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 0, bottom: 0, right: 0)
public static var rightButtonsInsetsRef: MaterialInsetsType = (top: 8, left: 0, bottom: 0, right: 0)
// border
public static var borderWidth: MaterialBorder = .None
public static var bordercolor: UIColor = MaterialColor.black
// color
public static var backgroundColor: UIColor = MaterialColor.white
// interaction
public static var userInteractionEnabled: Bool = true
// image
public static var contentsRect: CGRect = CGRectMake(0, 0, 1, 1)
public static var contentsCenter: CGRect = CGRectMake(0, 0, 1, 1)
public static var contentsScale: CGFloat = UIScreen.mainScreen().scale
public static var contentsGravity: MaterialGravity = .ResizeAspectFill
// position
public static var zPosition: CGFloat = 100
}
// pulseCollectionView
public extension MaterialTheme.pulseCollectionView {
// shadow
......
......@@ -31,18 +31,17 @@ public class NavigationBarView : MaterialView {
/**
:name: contentInsets
*/
public var contentInsets: MaterialInsets? {
public var contentInsets: MaterialInsets = .None {
didSet {
contentInsetsRef = nil == contentInsets ? nil : MaterialInsetsToValue(contentInsets!)
contentInsetsRef = MaterialInsetsToValue(contentInsets)
}
}
/**
:name: contentInsetsRef
*/
public var contentInsetsRef: MaterialInsetsType! {
public var contentInsetsRef: MaterialInsetsType = MaterialTheme.navigationBarView.contentInsetsRef {
didSet {
contentInsetsRef = nil == contentInsetsRef ? MaterialInsetsToValue(.None) : contentInsetsRef!
reloadView()
}
}
......@@ -50,18 +49,17 @@ public class NavigationBarView : MaterialView {
/**
:name: titleLabelInsets
*/
public var titleLabelInsets: MaterialInsets? {
public var titleLabelInsets: MaterialInsets = .None {
didSet {
titleLabelInsetsRef = nil == titleLabelInsets ? nil : MaterialInsetsToValue(titleLabelInsets!)
titleLabelInsetsRef = MaterialInsetsToValue(titleLabelInsets)
}
}
/**
:name: titleLabelInsetsRef
*/
public var titleLabelInsetsRef: MaterialInsetsType! {
public var titleLabelInsetsRef: MaterialInsetsType = MaterialTheme.navigationBarView.titleLabelInsetsRef {
didSet {
titleLabelInsetsRef = nil == titleLabelInsetsRef ? MaterialInsetsToValue(.None) : titleLabelInsetsRef!
reloadView()
}
}
......@@ -79,18 +77,17 @@ public class NavigationBarView : MaterialView {
/**
:name: detailLabelInsets
*/
public var detailLabelInsets: MaterialInsets? {
public var detailLabelInsets: MaterialInsets = .None {
didSet {
detailLabelInsetsRef = nil == detailLabelInsets ? nil : MaterialInsetsToValue(detailLabelInsets!)
detailLabelInsetsRef = MaterialInsetsToValue(detailLabelInsets)
}
}
/**
:name: detailLabelInsetsRef
*/
public var detailLabelInsetsRef: MaterialInsetsType! {
public var detailLabelInsetsRef: MaterialInsetsType = MaterialTheme.navigationBarView.detailLabelInsetsRef {
didSet {
detailLabelInsetsRef = nil == detailLabelInsetsRef ? MaterialInsetsToValue(.None) : detailLabelInsetsRef!
reloadView()
}
}
......@@ -108,18 +105,17 @@ public class NavigationBarView : MaterialView {
/**
:name: leftButtonsInsets
*/
public var leftButtonsInsets: MaterialInsets? {
public var leftButtonsInsets: MaterialInsets = .None {
didSet {
leftButtonsInsetsRef = nil == leftButtonsInsets ? nil : MaterialInsetsToValue(leftButtonsInsets!)
leftButtonsInsetsRef = MaterialInsetsToValue(leftButtonsInsets)
}
}
/**
:name: leftButtonsInsetsRef
*/
public var leftButtonsInsetsRef: MaterialInsetsType! {
public var leftButtonsInsetsRef: MaterialInsetsType = MaterialTheme.navigationBarView.leftButtonsInsetsRef {
didSet {
leftButtonsInsetsRef = nil == leftButtonsInsetsRef ? MaterialInsetsToValue(.None) : leftButtonsInsetsRef!
reloadView()
}
}
......@@ -141,18 +137,17 @@ public class NavigationBarView : MaterialView {
/**
:name: rightButtonsInsets
*/
public var rightButtonsInsets: MaterialInsets? {
public var rightButtonsInsets: MaterialInsets = .None {
didSet {
rightButtonsInsetsRef = nil == rightButtonsInsets ? nil : MaterialInsetsToValue(rightButtonsInsets!)
rightButtonsInsetsRef = MaterialInsetsToValue(rightButtonsInsets)
}
}
/**
:name: rightButtonsInsetsRef
*/
public var rightButtonsInsetsRef: MaterialInsetsType! {
public var rightButtonsInsetsRef: MaterialInsetsType = MaterialTheme.navigationBarView.rightButtonsInsetsRef {
didSet {
rightButtonsInsetsRef = nil == rightButtonsInsetsRef ? MaterialInsetsToValue(.None) : rightButtonsInsetsRef!
reloadView()
}
}
......@@ -207,11 +202,6 @@ public class NavigationBarView : MaterialView {
super.prepareView()
userInteractionEnabled = MaterialTheme.navigationBarView.userInteractionEnabled
backgroundColor = MaterialTheme.navigationBarView.backgroundColor
contentInsetsRef = MaterialTheme.navigationBarView.contentInsetsRef
titleLabelInsetsRef = MaterialTheme.navigationBarView.titleLabelInsetsRef
detailLabelInsetsRef = MaterialTheme.navigationBarView.detailLabelInsetsRef
leftButtonsInsetsRef = MaterialTheme.navigationBarView.leftButtonsInsetsRef
rightButtonsInsetsRef = MaterialTheme.navigationBarView.rightButtonsInsetsRef
contentsRect = MaterialTheme.navigationBarView.contentsRect
contentsCenter = MaterialTheme.navigationBarView.contentsCenter
......@@ -240,10 +230,10 @@ public class NavigationBarView : MaterialView {
if nil != titleLabel {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef!.top + titleLabelInsetsRef!.top
metrics["insetTop"] = contentInsetsRef.top + titleLabelInsetsRef.top
} else if nil != detailLabel {
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef!.top + detailLabelInsetsRef!.top
metrics["insetTop"] = contentInsetsRef.top + detailLabelInsetsRef.top
}
// title
......@@ -252,21 +242,21 @@ public class NavigationBarView : MaterialView {
views["titleLabel"] = v
addSubview(v)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + titleLabelInsetsRef!.left, right: contentInsetsRef!.right + titleLabelInsetsRef!.right)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef.left + titleLabelInsetsRef.left, right: contentInsetsRef.right + titleLabelInsetsRef.right)
}
// detail
if let v = detailLabel {
if nil != titleLabel {
verticalFormat += "-(insetB)"
metrics["insetB"] = titleLabelInsetsRef!.bottom + detailLabelInsetsRef!.top
metrics["insetB"] = titleLabelInsetsRef.bottom + detailLabelInsetsRef.top
}
verticalFormat += "-[detailLabel]"
views["detailLabel"] = v
addSubview(v)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef!.left + detailLabelInsetsRef!.left, right: contentInsetsRef!.right + detailLabelInsetsRef!.right)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef.left + detailLabelInsetsRef.left, right: contentInsetsRef.right + detailLabelInsetsRef.right)
}
// leftButtons
......@@ -289,10 +279,10 @@ public class NavigationBarView : MaterialView {
h += "[\(k)]"
addSubview(b)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef!.bottom + leftButtonsInsetsRef!.bottom)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef.bottom + leftButtonsInsetsRef.bottom)
}
addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : contentInsetsRef!.left + leftButtonsInsetsRef!.left, "left_right" : leftButtonsInsetsRef!.left + leftButtonsInsetsRef!.right], views: d))
addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : contentInsetsRef.left + leftButtonsInsetsRef.left, "left_right" : leftButtonsInsetsRef.left + leftButtonsInsetsRef.right], views: d))
}
}
......@@ -317,24 +307,24 @@ public class NavigationBarView : MaterialView {
}
addSubview(b)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef!.bottom + rightButtonsInsetsRef!.bottom)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef.bottom + rightButtonsInsetsRef.bottom)
}
addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : contentInsetsRef!.right + rightButtonsInsetsRef!.right, "right_left" : rightButtonsInsetsRef!.right + rightButtonsInsetsRef!.left], views: d))
addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : contentInsetsRef.right + rightButtonsInsetsRef.right, "right_left" : rightButtonsInsetsRef.right + rightButtonsInsetsRef.left], views: d))
}
}
if nil != detailLabel {
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef!.bottom + detailLabelInsetsRef!.bottom
metrics["insetBottom"] = contentInsetsRef.bottom + detailLabelInsetsRef.bottom
} else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailLabelInsetsRef!.bottom
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + detailLabelInsetsRef.bottom
}
} else if nil != titleLabel {
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef!.bottom + titleLabelInsetsRef!.bottom
metrics["insetBottom"] = contentInsetsRef.bottom + titleLabelInsetsRef.bottom
} else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + titleLabelInsetsRef!.bottom
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + titleLabelInsetsRef.bottom
}
}
......
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
import UIKit
public class SearchBarView : MaterialView, UITextFieldDelegate {
/**
:name: statusBarStyle
*/
public var statusBarStyle: MaterialStatusBarStyle! {
didSet {
UIApplication.sharedApplication().setStatusBarStyle(.LightContent == statusBarStyle ? .LightContent : .Default, animated: true)
}
}
/**
:name: textField
*/
public private(set) lazy var textField: UITextField = UITextField()
/**
:name: contentInsets
*/
public var contentInsets: MaterialInsets = .None {
didSet {
contentInsetsRef = MaterialInsetsToValue(contentInsets)
}
}
/**
:name: contentInsetsRef
*/
public var contentInsetsRef: MaterialInsetsType = MaterialTheme.searchBarView.contentInsetsRef {
didSet {
reloadView()
}
}
/**
:name: textFieldInsets
*/
public var textFieldInsets: MaterialInsets = .None {
didSet {
textFieldInsetsRef = MaterialInsetsToValue(textFieldInsets)
}
}
/**
:name: textFieldInsetsRef
*/
public var textFieldInsetsRef: MaterialInsetsType = MaterialTheme.searchBarView.textFieldInsetsRef {
didSet {
reloadView()
}
}
/**
:name: leftButtonsInsets
*/
public var leftButtonsInsets: MaterialInsets = .None {
didSet {
leftButtonsInsetsRef = MaterialInsetsToValue(leftButtonsInsets)
}
}
/**
:name: leftButtonsInsetsRef
*/
public var leftButtonsInsetsRef: MaterialInsetsType = MaterialTheme.searchBarView.leftButtonsInsetsRef {
didSet {
reloadView()
}
}
/**
:name: leftButtons
*/
public var leftButtons: Array<UIButton>? {
didSet {
if let v = leftButtons {
for b in v {
b.translatesAutoresizingMaskIntoConstraints = false
}
}
reloadView()
}
}
/**
:name: rightButtonsInsets
*/
public var rightButtonsInsets: MaterialInsets = .None {
didSet {
rightButtonsInsetsRef = MaterialInsetsToValue(rightButtonsInsets)
}
}
/**
:name: rightButtonsInsetsRef
*/
public var rightButtonsInsetsRef: MaterialInsetsType = MaterialTheme.searchBarView.rightButtonsInsetsRef {
didSet {
reloadView()
}
}
/**
:name: rightButtons
*/
public var rightButtons: Array<UIButton>? {
didSet {
if let v = rightButtons {
for b in v {
b.translatesAutoresizingMaskIntoConstraints = false
}
}
reloadView()
}
}
/**
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
/**
:name: init
*/
public override init(frame: CGRect) {
super.init(frame: frame)
}
/**
:name: init
*/
public convenience init() {
self.init(frame: CGRectMake(MaterialTheme.searchBarView.x, MaterialTheme.searchBarView.y, MaterialTheme.searchBarView.width, MaterialTheme.searchBarView.height))
}
/**
:name: init
*/
public convenience init?(leftButtons: Array<UIButton>? = nil, rightButtons: Array<UIButton>? = nil) {
self.init(frame: CGRectMake(MaterialTheme.searchBarView.x, MaterialTheme.searchBarView.y, MaterialTheme.searchBarView.width, MaterialTheme.searchBarView.height))
prepareProperties(leftButtons, rightButtons: rightButtons)
}
/**
:name: prepareView
*/
public override func prepareView() {
super.prepareView()
userInteractionEnabled = MaterialTheme.searchBarView.userInteractionEnabled
backgroundColor = MaterialTheme.searchBarView.backgroundColor
contentsRect = MaterialTheme.searchBarView.contentsRect
contentsCenter = MaterialTheme.searchBarView.contentsCenter
contentsScale = MaterialTheme.searchBarView.contentsScale
contentsGravity = MaterialTheme.searchBarView.contentsGravity
shadowDepth = MaterialTheme.searchBarView.shadowDepth
shadowColor = MaterialTheme.searchBarView.shadowColor
zPosition = MaterialTheme.searchBarView.zPosition
borderWidth = MaterialTheme.searchBarView.borderWidth
borderColor = MaterialTheme.searchBarView.bordercolor
prepareTextField()
reloadView()
}
/**
:name: reloadView
*/
public func reloadView() {
// clear constraints so new ones do not conflict
removeConstraints(constraints)
for v in subviews {
v.removeFromSuperview()
}
var verticalFormat: String = "V:|"
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var metrics: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
verticalFormat += "-(insetTop)"
metrics["insetTop"] = contentInsetsRef.top + textFieldInsetsRef.top
// textField
verticalFormat += "-[textField]"
views["textField"] = textField
addSubview(textField)
print(contentInsetsRef)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: textField, left: contentInsetsRef.left + textFieldInsetsRef.left, right: contentInsetsRef.right + textFieldInsetsRef.right)
// leftButtons
if let v = leftButtons {
if 0 < v.count {
var h: String = "H:|"
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var i: Int = 0
for b in v {
let k: String = "b\(i)"
d[k] = b
if 0 == i++ {
h += "-(left)-"
} else {
h += "-(left_right)-"
}
h += "[\(k)]"
addSubview(b)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef.bottom + leftButtonsInsetsRef.bottom)
}
addConstraints(MaterialLayout.constraint(h, options: [], metrics: ["left" : contentInsetsRef.left + leftButtonsInsetsRef.left, "left_right" : leftButtonsInsetsRef.left + leftButtonsInsetsRef.right], views: d))
}
}
// rightButtons
if let v = rightButtons {
if 0 < v.count {
var h: String = "H:"
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var i: Int = v.count - 1
for b in v {
let k: String = "b\(i)"
d[k] = b
h += "[\(k)]"
if 0 == i-- {
h += "-(right)-"
} else {
h += "-(right_left)-"
}
addSubview(b)
MaterialLayout.alignFromBottom(self, child: b, bottom: contentInsetsRef.bottom + rightButtonsInsetsRef.bottom)
}
addConstraints(MaterialLayout.constraint(h + "|", options: [], metrics: ["right" : contentInsetsRef.right + rightButtonsInsetsRef.right, "right_left" : rightButtonsInsetsRef.right + rightButtonsInsetsRef.left], views: d))
}
}
if nil == metrics["insetC"] {
metrics["insetBottom"] = contentInsetsRef.bottom + textFieldInsetsRef.bottom
} else {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + textFieldInsetsRef.bottom
}
if 0 < views.count {
verticalFormat += "-(insetBottom)-|"
addConstraints(MaterialLayout.constraint(verticalFormat, options: [], metrics: metrics, views: views))
}
}
//
// :name: prepareProperties
//
internal func prepareProperties(leftButtons: Array<UIButton>?, rightButtons: Array<UIButton>?) {
self.leftButtons = leftButtons
self.rightButtons = rightButtons
}
//
// :name: prepareTextField
//
internal func prepareTextField() {
textField.translatesAutoresizingMaskIntoConstraints = false
textField.delegate = self
textField.placeholder = "Search"
}
public func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
backgroundColor = MaterialColor.white
return true
}
public func textFieldShouldEndEditing(textField: UITextField) -> Bool {
backgroundColor = MaterialColor.blue.accent3
return true
}
}
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