Commit fe5afa24 by Daniel Dahan

master: merged development

parents 994edd5b b65ca0e8
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'MK' s.name = 'MK'
s.version = '1.3.0' s.version = '1.4.0'
s.license = { :type => "AGPLv3+", :file => "LICENSE" } s.license = { :type => "AGPLv3+", :file => "LICENSE" }
s.summary = 'A Material Design Framework In Swift' s.summary = 'A Material Design Framework In Swift'
s.homepage = 'http://materialkit.io' s.homepage = 'http://materialkit.io'
......
![MaterialKit](http://materialkit.io/MaterialKitLogo.png) # MaterialKit
# Build Beautiful Software ### Build Beautiful Software
* [CocoaPods (MK)](https://cocoapods.org/?q=MK) * [CocoaPods (MK)](https://cocoapods.org/?q=MK)
### CocoaPods Support ### CocoaPods Support
MaterialKit is now on CocoaPods under the name [MK](https://cocoapods.org/?q=MK). MaterialKit is now on CocoaPods under the name [MK](https://cocoapods.org/?q=MK).
### Floating Action Button
![MaterialKitPreview](http://www.materialkit.io/MaterialKitPreview.gif) Make a call to action with a Floating Action Button.
### Floating Action Button ![MaterialKitPreview](http://www.materialkit.io/fabbuttonpreview.gif)
```swift ```swift
var button: FabButton = FabButton() var button: FabButton = FabButton()
button.setTitle("+", forState: .Normal)
button.titleLabel!.font = UIFont(name: "Arial", size: 32)
view.addSubview(button)
Layout.size(view, child: button, width: 60, height: 60)
``` ```
### Flat Button ### Raised Button
Use a Raised Button to capture attention.
![MaterialKitPreview](http://www.materialkit.io/raisedbuttonpreview.gif)
```swift ```swift
var button: FlatButton = FlatButton() var button: RaisedButton = RaisedButton()
button.setTitle("Raised", forState: .Normal)
view.addSubview(button)
Layout.size(view, child: button, width: 200, height: 60)
``` ```
### Raised Button ### Flat Button
Keep it simple and elegant with a Flat Button.
![MaterialKitPreview](http://www.materialkit.io/flatbuttonpreview.gif)
```swift ```swift
var button: RaisedButton = RaisedButton() var button: RaisedButton = RaisedButton()
button.setTitle("Flat", forState: .Normal)
view.addSubview(button)
Layout.size(view, child: button, width: 200, height: 60)
```
### Basic Card
Easily make cards with fully customizable components.
![MaterialKitPreview](http://www.materialkit.io/basiccardpreview.gif)
```swift
var card: BasicCard = BasicCard()
// add a title
card.titleLabel = UILabel()
card.titleLabel!.text = "Card Title"
// add a body of text
card.detailTextLabel = UILabel()
card.detailTextLabel!.text = "I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively."
// add a divider for buttons
card.divider = UIView()
// add a couple buttons
var cancelButton: FlatButton = FlatButton()
cancelButton.pulseColor = MaterialTheme.blueGrey.darken3
cancelButton.setTitle("Cancel", forState: .Normal)
cancelButton.setTitleColor(MaterialTheme.yellow.darken3, forState: .Normal)
var okButton: FlatButton = FlatButton()
okButton.pulseColor = MaterialTheme.blueGrey.darken3
okButton.setTitle("Okay", forState: .Normal)
okButton.setTitleColor(MaterialTheme.yellow.darken3, forState: .Normal)
card.buttons = [cancelButton, okButton]
view.addSubview(card)
``` ```
### Side Navigation Controller ### Side Navigation Controller
Add a sleek Side Navigation to give your users a wonderful experience.
![MaterialKitPreview](http://www.materialkit.io/sidenavpreview.gif)
```swift ```swift
class AppDelegate: UIResponder, UIApplicationDelegate, SideNavDelegate { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var window: UIWindow? sideNav = SideNavController(mainViewController: MainViewController(), leftViewController: LeftViewController(), rightViewController: RightViewController())
var sideNav: SideNavController? sideNav!.delegate = self
private lazy var graph: Graph = Graph() window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.rootViewController = sideNav
window!.makeKeyAndVisible()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { return true
sideNav = SideNavController(mainViewController: MainViewController(), leftViewController: LeftViewController(), rightViewController: RightViewController()) }
sideNav!.delegate = self
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.rootViewController = sideNav
window!.makeKeyAndVisible()
return true
}
...
``` ```
### License ### License
......
//
// 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 AddFabButton : FabButton {
/**
:name: lineWidth
*/
public var lineWidth: CGFloat = 2
//
// :name: verticalLine
//
private var verticalLine: UIView!
//
// :name: horizontalLine
//
private var horizontalLine: UIView!
//
// :name: prepareButton
//
public override func prepareButton() {
super.prepareButton()
prepareVerticalLine()
prepareHorizontalLine()
}
//
// :name: prepareVerticalLine
//
private func prepareVerticalLine() {
verticalLine = UIView(frame: CGRectMake(0, 0, lineWidth, CGRectGetHeight(backgroundColorView.frame) / 3))
verticalLine.backgroundColor = .whiteColor()
verticalLine.center = backgroundColorView.center
backgroundColorView.addSubview(verticalLine)
}
//
// :name: prepareHorizontalLine
//
private func prepareHorizontalLine() {
horizontalLine = UIView(frame: CGRectMake(0, 0, CGRectGetWidth(backgroundColorView.frame) / 3, lineWidth))
horizontalLine.backgroundColor = .whiteColor()
horizontalLine.center = backgroundColorView.center
backgroundColorView.addSubview(horizontalLine)
}
}
...@@ -19,88 +19,132 @@ ...@@ -19,88 +19,132 @@
import UIKit import UIKit
import QuartzCore import QuartzCore
public class BasicCard : MaterialPulseView { public class BasicCard : MaterialCard {
public lazy var cancelButton: FlatButton = FlatButton() //
public lazy var otherButton: FlatButton = FlatButton() // :name: layoutConstraints
public lazy var buttonColor: UIColor = UIColor(red: 255.0/255.0, green: 156.0/255.0, blue: 38.0/255.0, alpha: 1.0) //
public lazy var titleLabel: UILabel = UILabel() internal lazy var layoutConstraints: Array<NSLayoutConstraint> = Array<NSLayoutConstraint>()
public lazy var detailTextLabel: UILabel = UILabel()
public lazy var horizontalSeparator: UIView = UIView()
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
public required init(frame: CGRect) {
super.init(frame: frame)
}
internal override func initialize() {
setupTitleLabel()
setupDetailTextLabel()
setupHorizontalLineSeparator()
setupButtons()
super.initialize()
}
internal override func constrainSubviews() { //
super.constrainSubviews() // :name: views
addConstraints(Layout.constraint("H:|-(20)-[titleLabel]-(20)-|", options: nil, metrics: nil, views: views)) //
addConstraints(Layout.constraint("H:|-(20)-[detailTextLabel]-(20)-|", options: nil, metrics: nil, views: views)) internal lazy var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
addConstraints(Layout.constraint("H:|[horizontalSeparator]|", options: nil, metrics: nil, views: views))
addConstraints(Layout.constraint("H:|-(10)-[cancelButton(80)]-(10)-[otherButton(80)]", options: nil, metrics: nil, views: views)) //
addConstraints(Layout.constraint("V:|-(20)-[titleLabel(22)]-(10)-[detailTextLabel]-(20)-[line(1)]-(10)-[cancelButton]-(10)-|", options: nil, metrics: nil, views: views)) // :name: divider
addConstraints(Layout.constraint("V:|-(20)-[titleLabel(22)]-(10)-[detailTextLabel]-(20)-[line(1)]-(10)-[otherButton]-(10)-|", options: nil, metrics: nil, views: views)) //
public var divider: UIView? {
didSet {
divider!.setTranslatesAutoresizingMaskIntoConstraints(false)
divider!.backgroundColor = MaterialTheme.blueGrey.color
addSubview(divider!)
prepareCard()
}
}
/**
:name: titleLabel
*/
public var titleLabel: UILabel? {
didSet {
titleLabel!.setTranslatesAutoresizingMaskIntoConstraints(false)
titleLabel!.textColor = MaterialTheme.white.color
titleLabel!.font = Roboto.regularWithSize(22.0)
addSubview(titleLabel!)
prepareCard()
}
}
/**
:name: detailTextLabel
*/
public var detailTextLabel: UILabel? {
didSet {
detailTextLabel!.setTranslatesAutoresizingMaskIntoConstraints(false)
detailTextLabel!.textColor = MaterialTheme.white.color
detailTextLabel!.font = Roboto.lightWithSize(16.0)
detailTextLabel!.numberOfLines = 0
detailTextLabel!.lineBreakMode = .ByWordWrapping
addSubview(detailTextLabel!)
prepareCard()
}
} }
private func setupTitleLabel() { /**
titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false) :name: buttons
titleLabel.font = Roboto.regularWithSize(22.0) */
titleLabel.textColor = UIColor.whiteColor() public var buttons: Array<MaterialButton>? {
titleLabel.text = "Card Title" didSet {
addSubview(titleLabel) prepareCard()
views["titleLabel"] = titleLabel }
} }
private func setupDetailTextLabel() { //
detailTextLabel.setTranslatesAutoresizingMaskIntoConstraints(false) // :name: prepareView
detailTextLabel.font = Roboto.lightWithSize(16.0) //
detailTextLabel.textColor = UIColor.whiteColor() internal override func prepareView() {
detailTextLabel.text = "I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively." super.prepareView()
detailTextLabel.numberOfLines = 0 backgroundColor = MaterialTheme.blueGrey.darken1
detailTextLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping }
addSubview(detailTextLabel)
views["detailTextLabel"] = detailTextLabel //
} // :name: prepareCard
//
private func setupHorizontalLineSeparator() { internal override func prepareCard() {
horizontalSeparator.setTranslatesAutoresizingMaskIntoConstraints(false) super.prepareCard()
horizontalSeparator.backgroundColor = UIColor.whiteColor() prepareShadow()
horizontalSeparator.alpha = 0.2
addSubview(horizontalSeparator) // deactivate and clear all constraints
views["horizontalSeparator"] = horizontalSeparator NSLayoutConstraint.deactivateConstraints(layoutConstraints)
} layoutConstraints.removeAll(keepCapacity: false)
private func setupButtons() { // detect all components and create constraints
setupCancelButton() var verticalFormat: String = "V:|"
setupOtherButton()
} // title
if nil != titleLabel {
private func setupCancelButton() { layoutConstraints += Layout.constraint("H:|-(20)-[titleLabel]-(20)-|", options: nil, metrics: nil, views: ["titleLabel": titleLabel!])
cancelButton.setTranslatesAutoresizingMaskIntoConstraints(false) verticalFormat += "-(20)-[titleLabel(22)]"
cancelButton.setTitle("Cancel", forState: .Normal) views["titleLabel"] = titleLabel!
cancelButton.setTitleColor(buttonColor, forState: .Normal) }
cancelButton.pulseColor = buttonColor
addSubview(cancelButton) // details
views["cancelButton"] = cancelButton if nil != detailTextLabel {
} layoutConstraints += Layout.constraint("H:|-(20)-[detailTextLabel]-(20)-|", options: nil, metrics: nil, views: ["detailTextLabel": detailTextLabel!])
verticalFormat += "-(20)-[detailTextLabel]"
private func setupOtherButton() { views["detailTextLabel"] = detailTextLabel!
otherButton.setTranslatesAutoresizingMaskIntoConstraints(false) }
otherButton.setTitle("Confirm", forState: .Normal)
otherButton.setTitleColor(buttonColor, forState: .Normal) if nil != buttons {
otherButton.pulseColor = buttonColor // divider
addSubview(otherButton) if nil != divider {
views["otherButton"] = otherButton layoutConstraints += Layout.constraint("H:|[divider]|", options: nil, metrics: nil, views: ["divider": divider!])
} views["divider"] = divider!
verticalFormat += "-(20)-[divider(1)]"
}
// buttons
var horizontalFormat: String = "H:|"
var buttonViews: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
for var i: Int = 0, l: Int = buttons!.count; i < l; ++i {
let button: MaterialButton = buttons![i]
addSubview(button)
buttonViews["button\(i)"] = button
views["button\(i)"] = button as AnyObject
horizontalFormat += "-(10)-[button\(i)]"
layoutConstraints += Layout.constraint(verticalFormat + "-(10)-[button\(i)]-(10)-|", options: nil, metrics: nil, views: views)
}
layoutConstraints += Layout.constraint(horizontalFormat, options: nil, metrics: nil, views: buttonViews)
} else {
verticalFormat += "-(20)-|"
}
// combine constraints
if 0 < layoutConstraints.count {
layoutConstraints += Layout.constraint(verticalFormat, options: nil, metrics: nil, views: views)
NSLayoutConstraint.activateConstraints(layoutConstraints)
}
}
} }
...@@ -22,11 +22,18 @@ public class FabButton : MaterialButton { ...@@ -22,11 +22,18 @@ public class FabButton : MaterialButton {
// //
// :name: prepareButton // :name: prepareButton
// //
internal override func prepareView() {
super.prepareView()
setTitleColor(MaterialTheme.white.color, forState: .Normal)
backgroundColor = MaterialTheme.red.darken1
}
//
// :name: prepareButton
//
internal override func prepareButton() { internal override func prepareButton() {
super.prepareButton() super.prepareButton()
prepareShadow() prepareShadow()
backgroundColor = .redColor()
pulseColor = .whiteColor()
backgroundColorView.layer.cornerRadius = bounds.width / 2 backgroundColorView.layer.cornerRadius = bounds.width / 2
} }
......
...@@ -20,13 +20,21 @@ import UIKit ...@@ -20,13 +20,21 @@ import UIKit
public class FlatButton : MaterialButton { public class FlatButton : MaterialButton {
// //
// :name: prepareView
//
internal override func prepareView() {
super.prepareView()
setTitleColor(MaterialTheme.indigo.darken1, forState: .Normal)
pulseColor = MaterialTheme.indigo.darken1
backgroundColor = MaterialTheme.clear.color
contentEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 20)
}
//
// :name: prepareButton // :name: prepareButton
// //
internal override func prepareButton() { internal override func prepareButton() {
super.prepareButton() super.prepareButton()
setTitleColor(UIColor.purpleColor(), forState: .Normal)
pulseColor = .purpleColor()
backgroundColor = .clearColor()
backgroundColorView.layer.cornerRadius = 3 backgroundColorView.layer.cornerRadius = 3
} }
...@@ -36,8 +44,8 @@ public class FlatButton : MaterialButton { ...@@ -36,8 +44,8 @@ public class FlatButton : MaterialButton {
internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) { internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.pulseBegan(touches, withEvent: event) super.pulseBegan(touches, withEvent: event)
UIView.animateWithDuration(0.3, animations: { UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10) self.pulseView!.transform = CGAffineTransformMakeScale(4, 4)
self.transform = CGAffineTransformMakeScale(1.05, 1.1) self.transform = CGAffineTransformMakeScale(1.05, 1.05)
}) })
} }
} }
////
//// 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/>.
////
// //
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors. //import UIKit
// //
// This program is free software: you can redistribute it and/or modify //public class ImageCard : MaterialPulseView {
// it under the terms of the GNU Affero General Public License as published // public lazy var imageView: UIImageView = UIImageView()
// by the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. // public required init(coder aDecoder: NSCoder) {
// // super.init(coder: aDecoder)
// 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 // public required init(frame: CGRect) {
// GNU Affero General Public License for more details. // super.init(frame: frame)
// // }
// 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 // internal override func initialize() {
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>. // prepareImageView()
// // super.initialize()
// }
import UIKit //
// internal override func constrainSubviews() {
public class ImageCard : MaterialPulseView { // super.constrainSubviews()
public lazy var imageView: UIImageView = UIImageView() // addConstraints(Layout.constraint("H:|[imageView]|", options: nil, metrics: nil, views: views))
// addConstraints(Layout.constraint("V:|[imageView]|", options: nil, metrics: nil, views: views))
public required init(coder aDecoder: NSCoder) { // }
super.init(coder: aDecoder) //
} // private func prepareImageView() {
// imageView.setTranslatesAutoresizingMaskIntoConstraints(false)
public required init(frame: CGRect) { // imageView.contentMode = .ScaleAspectFill
super.init(frame: frame) // imageView.userInteractionEnabled = false
} // imageView.clipsToBounds = true
// addSubview(imageView)
internal override func initialize() { // views["imageView"] = imageView
setupImageView() // }
super.initialize() //}
}
internal override func constrainSubviews() {
super.constrainSubviews()
addConstraints(Layout.constraint("H:|[imageView]|", options: nil, metrics: nil, views: views))
addConstraints(Layout.constraint("V:|[imageView]|", options: nil, metrics: nil, views: views))
}
private func setupImageView() {
imageView.setTranslatesAutoresizingMaskIntoConstraints(false)
imageView.contentMode = .ScaleAspectFill
imageView.userInteractionEnabled = false
imageView.clipsToBounds = true
addSubview(imageView)
views["imageView"] = imageView
}
}
////
//// RevealCard.swift
//// MaterialKit
////
//// Created by Adam Dahan on 2015-08-26.
//// Copyright (c) 2015 GraphKit Inc. All rights reserved.
////
//
//import UIKit
//
//public class ImageRevealCard : ImageCard {
//
// private lazy var revealView: UIView = UIView()
// private lazy var tapGesture: UITapGestureRecognizer = UITapGestureRecognizer()
// private lazy var metrics: Dictionary <String, AnyObject> = Dictionary <String, AnyObject>()
// private var topLayoutConstraint: NSLayoutConstraint!
// private lazy var hideRevealViewButton: UIButton = UIButton()
//
// public required init(coder aDecoder: NSCoder) {
// super.init(coder: aDecoder)
// }
//
// public required init(frame: CGRect) {
// super.init(frame: frame)
// }
//
// internal override func initialize() {
// prepareTapGestures()
// prepareRevealView()
// prepareHideRevealViewButton()
// super.initialize()
// }
//
// public override func layoutSubviews() {
// super.layoutSubviews()
// revealView.frame = CGRectMake(0, 0, bounds.width, bounds.height)
// hideRevealViewButton.frame = CGRectMake(CGRectGetMaxX(revealView.frame) - 50, 10, 40, 40)
// }
//
// private func prepareTapGestures() {
// tapGesture.addTarget(self, action: "showRevealView")
// imageView.userInteractionEnabled = true
// addGestureRecognizer(tapGesture)
// }
//
// private func prepareRevealView() {
// revealView.backgroundColor = .whiteColor()
// revealView.hidden = true
// imageView.addSubview(revealView)
// }
//
// private func prepareHideRevealViewButton() {
// hideRevealViewButton.setImage(UIImage(named: "ic_clear"), forState: .Normal)
// hideRevealViewButton.tintColor = .whiteColor()
// hideRevealViewButton.addTarget(self, action: "hideRevealView", forControlEvents: UIControlEvents.TouchUpInside)
// revealView.addSubview(hideRevealViewButton)
// }
//
// internal func showRevealView() {
// removeTapGestures()
// revealView.hidden = false
// revealView.frame = CGRectMake(0, bounds.height, bounds.width, bounds.height)
// UIView.animateWithDuration(0.3, animations: { () -> Void in
// var frame = self.revealView.frame
// frame.origin.y -= self.bounds.height
// self.revealView.frame = frame
// })
// }
//
// internal func hideRevealView() {
// UIView.animateWithDuration(0.3, animations: { () -> Void in
// var frame = self.revealView.frame
// frame.origin.y = self.bounds.height
// self.revealView.frame = frame
// }) { (finished) -> Void in
// self.revealView.hidden = true
// self.prepareTapGestures()
// }
// }
//
// private func removeTapGestures() {
// removeGestureRecognizer(tapGesture)
// }
//}
//
//
//
////
//// ImageTextButtonCard.swift
//// MaterialKit
////
//// Created by Adam Dahan on 2015-08-26.
//// Copyright (c) 2015 GraphKit Inc. All rights reserved.
////
//
//import UIKit
//
//public class ImageTextButtonCard : MaterialPulseView {
// public lazy var imageView: UIImageView = UIImageView()
// public lazy var titleLabel: UILabel = UILabel()
// public lazy var descriptionContainerView: UIView = UIView()
// public lazy var descriptionLabel: UILabel = UILabel()
// public lazy var horizontalSeparator: UIView = UIView()
// public lazy var button: FlatButton = FlatButton()
//
// public required init(coder aDecoder: NSCoder) {
// super.init(coder: aDecoder)
// }
//
// public required init(frame: CGRect) {
// super.init(frame: frame)
// }
//
// internal override func initialize() {
// prepareImageView()
// prepareTitleLabel()
// prepareDescriptionContainerView()
// prepareDescriptionLabel()
// prepareHorizontalSeparator()
// prepareButton()
// super.initialize()
// }
//
// internal override func constrainSubviews() {
// super.constrainSubviews()
// addConstraints(Layout.constraint("H:|[imageView]|", options: nil, metrics: nil, views: views))
// imageView.addConstraints(Layout.constraint("H:|-20-[titleLabel]-(20)-|", options: nil, metrics: nil, views: views))
// imageView.addConstraints(Layout.constraint("V:[titleLabel(45)]|", options: nil, metrics: nil, views: views))
// addConstraints(Layout.constraint("H:|[descriptionContainerView]|", options: nil, metrics: nil, views: views))
// descriptionContainerView.addConstraints(Layout.constraint("H:|-20-[descriptionLabel]-(20)-|", options: nil, metrics: nil, views: views))
// addConstraints(Layout.constraint("V:|[imageView][descriptionContainerView(160)]|", options: nil, metrics: nil, views: views))
// descriptionContainerView.addConstraints(Layout.constraint("H:|[horizontalSeparator]|", options: nil, metrics: nil, views: views))
// descriptionContainerView.addConstraints(Layout.constraint("H:|-(10)-[button(70)]", options: nil, metrics: nil, views: views))
// descriptionContainerView.addConstraints(Layout.constraint("V:|-(20)-[descriptionLabel]-(20)-[horizontalSeparator(1)]-(10)-[button(30)]-(10)-|", options: nil, metrics: nil, views: views))
// }
//
// private func prepareImageView() {
// imageView.setTranslatesAutoresizingMaskIntoConstraints(false)
// imageView.contentMode = .ScaleAspectFill
// imageView.userInteractionEnabled = false
// imageView.clipsToBounds = true
// addSubview(imageView)
// views["imageView"] = imageView
// }
//
// private func prepareTitleLabel() {
// titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
// titleLabel.font = Roboto.mediumWithSize(18)
// titleLabel.textColor = .whiteColor()
// titleLabel.text = "Card Title"
// titleLabel.layer.shadowOffset = CGSizeMake(1, 1)
// titleLabel.layer.shadowOpacity = 0.4
// titleLabel.layer.shadowRadius = 5.0
// imageView.addSubview(titleLabel)
// views["titleLabel"] = titleLabel
// }
//
// private func prepareDescriptionContainerView() {
// descriptionContainerView.setTranslatesAutoresizingMaskIntoConstraints(false)
// descriptionContainerView.backgroundColor = UIColor.whiteColor()
// addSubview(descriptionContainerView)
// views["descriptionContainerView"] = descriptionContainerView
// }
//
// private func prepareDescriptionLabel() {
// descriptionLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
// descriptionLabel.font = Roboto.lightWithSize(14)
// descriptionLabel.textColor = .darkTextColor()
// descriptionLabel.numberOfLines = 0
// descriptionLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
// descriptionLabel.text = "I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively."
// descriptionContainerView.addSubview(descriptionLabel)
// views["descriptionLabel"] = descriptionLabel
// }
//
// private func prepareHorizontalSeparator() {
// horizontalSeparator.setTranslatesAutoresizingMaskIntoConstraints(false)
// horizontalSeparator.backgroundColor = UIColor.darkGrayColor()
// horizontalSeparator.alpha = 0.2
// descriptionContainerView.addSubview(horizontalSeparator)
// views["horizontalSeparator"] = horizontalSeparator
// }
//
// private func prepareButton() {
// button.setTranslatesAutoresizingMaskIntoConstraints(false)
// button.setTitle("Cancel", forState: .Normal)
// button.setTitleColor(UIColor(red: 255.0/255.0, green: 156.0/255.0, blue: 38.0/255.0, alpha: 1.0), forState: .Normal)
// button.layer.shadowOpacity = 0
// button.titleLabel!.font = Roboto.lightWithSize(16.0)
// button.pulseColor = UIColor(red: 255.0/255.0, green: 156.0/255.0, blue: 38.0/255.0, alpha: 1.0)
// descriptionContainerView.addSubview(button)
// views["button"] = button
// }
//}
////
//// ImageTextCard.swift
//// MaterialKit
////
//// Created by Adam Dahan on 2015-08-26.
//// Copyright (c) 2015 GraphKit Inc. All rights reserved.
////
//
//import UIKit
//
//public class ImageTextCard : MaterialPulseView {
// public lazy var imageView: UIImageView = UIImageView()
// public lazy var titleLabel: UILabel = UILabel()
// public lazy var descriptionContainerView: UIView = UIView()
// public lazy var descriptionLabel: UILabel = UILabel()
// public lazy var horizontalSeparator: UIView = UIView()
// public lazy var ctaButton: FlatButton = FlatButton()
// public lazy var showsCTA: Bool = false
//
// public required init(coder aDecoder: NSCoder) {
// super.init(coder: aDecoder)
// }
//
// public required init(frame: CGRect) {
// super.init(frame: frame)
// }
//
// internal override func initialize() {
// prepareImageView()
// prepareTitleLabel()
// prepareDescriptionContainerView()
// prepareDescriptionLabel()
// if showsCTA {
// prepareHorizontalSeparator()
// prepareCTAButton()
// }
// super.initialize()
// }
//
// internal override func constrainSubviews() {
// super.constrainSubviews()
// addConstraints(Layout.constraint("H:|[imageView]|", options: nil, metrics: nil, views: views))
// imageView.addConstraints(Layout.constraint("H:|-20-[titleLabel]-(20)-|", options: nil, metrics: nil, views: views))
// imageView.addConstraints(Layout.constraint("V:[titleLabel(45)]|", options: nil, metrics: nil, views: views))
// addConstraints(Layout.constraint("H:|[descriptionContainerView]|", options: nil, metrics: nil, views: views))
// descriptionContainerView.addConstraints(Layout.constraint("H:|-20-[descriptionLabel]-(20)-|", options: nil, metrics: nil, views: views))
// descriptionContainerView.addConstraints(Layout.constraint("V:|-(20)-[descriptionLabel]-(20)-|", options: nil, metrics: nil, views: views))
// addConstraints(Layout.constraint("V:|[imageView][descriptionContainerView(120)]|", options: nil, metrics: nil, views: views))
// if showsCTA {
// descriptionContainerView.addConstraints(Layout.constraint("H:|[horizontalSeparator]|", options: nil, metrics: nil, views: views))
// descriptionContainerView.addConstraints(Layout.constraint("V:|-(20)-[descriptionLabel]-(20)-[horizontalSeparator(1)]-(20)-|", options: nil, metrics: nil, views: views))
// }
// }
//
// private func prepareImageView() {
// imageView.setTranslatesAutoresizingMaskIntoConstraints(false)
// imageView.contentMode = .ScaleAspectFill
// imageView.userInteractionEnabled = false
// imageView.clipsToBounds = true
// addSubview(imageView)
// views["imageView"] = imageView
// }
//
// private func prepareTitleLabel() {
// titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
// titleLabel.font = Roboto.mediumWithSize(18)
// titleLabel.textColor = .whiteColor()
// titleLabel.text = "Card Title"
// titleLabel.layer.shadowOffset = CGSizeMake(1, 1)
// titleLabel.layer.shadowOpacity = 0.4
// titleLabel.layer.shadowRadius = 5.0
// imageView.addSubview(titleLabel)
// views["titleLabel"] = titleLabel
// }
//
// private func prepareDescriptionContainerView() {
// descriptionContainerView.setTranslatesAutoresizingMaskIntoConstraints(false)
// descriptionContainerView.backgroundColor = UIColor.whiteColor()
// addSubview(descriptionContainerView)
// views["descriptionContainerView"] = descriptionContainerView
// }
//
// private func prepareDescriptionLabel() {
// descriptionLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
// descriptionLabel.font = Roboto.lightWithSize(14)
// descriptionLabel.textColor = .darkTextColor()
// descriptionLabel.numberOfLines = 0
// descriptionLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
// descriptionLabel.text = "I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively."
// descriptionContainerView.addSubview(descriptionLabel)
// views["descriptionLabel"] = descriptionLabel
// }
//
// private func prepareHorizontalSeparator() {
// horizontalSeparator.setTranslatesAutoresizingMaskIntoConstraints(false)
// horizontalSeparator.backgroundColor = UIColor.whiteColor()
// horizontalSeparator.alpha = 0.2
// descriptionContainerView.addSubview(horizontalSeparator)
// views["horizontalSeparator"] = horizontalSeparator
// }
//
// private func prepareCTAButton() {
//
// }
//}
...@@ -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.3.0</string> <string>1.4.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -46,6 +46,24 @@ public struct Layout { ...@@ -46,6 +46,24 @@ public struct Layout {
} }
/** /**
:name: expandToParentSize
*/
public static func expandToParentSize(parent: UIView, child: UIView) {
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint("H:|[child]|", options: nil, metrics: nil, views: views))
parent.addConstraints(constraint("V:|[child]|", options: nil, metrics: nil, views: views))
}
/**
:name: expandToParentSizeWithPad
*/
public static func expandToParentSizeWithPad(parent: UIView, child: UIView, left: CGFloat, bottom: CGFloat, right: CGFloat, top: CGFloat) {
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint("H:|-(left)-[child]-(right)-|", options: nil, metrics: ["left": left, "right": right], views: views))
parent.addConstraints(constraint("V:|-(top)-[child]-(bottom)-|", options: nil, metrics: ["bottom": bottom, "top": top], views: views))
}
/**
:name: alignFromTopLeft :name: alignFromTopLeft
*/ */
public static func alignFromTopLeft(parent: UIView, child: UIView, top: CGFloat, left: CGFloat) { public static func alignFromTopLeft(parent: UIView, child: UIView, top: CGFloat, left: CGFloat) {
...@@ -84,11 +102,23 @@ public struct Layout { ...@@ -84,11 +102,23 @@ public struct Layout {
parent.addConstraints(constraint("H:[child]-(right)-|", options: nil, metrics: metrics, views: views)) parent.addConstraints(constraint("H:[child]-(right)-|", options: nil, metrics: metrics, views: views))
parent.addConstraints(constraint("V:[child]-(bottom)-|", options: nil, metrics: metrics, views: views)) parent.addConstraints(constraint("V:[child]-(bottom)-|", options: nil, metrics: metrics, views: views))
} }
/**
:name: alignAllSides
*/
public static func alignAllSides(parent: UIView, child: UIView) {
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint("H:|[child]|", options: nil, metrics: nil, views: views))
parent.addConstraints(constraint("V:|[child]|", options: nil, metrics: nil, views: views))
}
/** /**
:name: constraint :name: constraint
*/ */
public static func constraint(format: String, options: NSLayoutFormatOptions, metrics: Dictionary<String, AnyObject>?, views: Dictionary<String, AnyObject>) -> Array<NSLayoutConstraint> { public static func constraint(format: String, options: NSLayoutFormatOptions, metrics: Dictionary<String, AnyObject>?, views: Dictionary<String, AnyObject>) -> Array<NSLayoutConstraint> {
for (_, v) in views {
v.setTranslatesAutoresizingMaskIntoConstraints(false)
}
return NSLayoutConstraint.constraintsWithVisualFormat( return NSLayoutConstraint.constraintsWithVisualFormat(
format, format,
options: options, options: options,
......
...@@ -33,15 +33,18 @@ public class MaterialButton : UIButton { ...@@ -33,15 +33,18 @@ public class MaterialButton : UIButton {
:name: backgroundColor :name: backgroundColor
*/ */
public override var backgroundColor: UIColor? { public override var backgroundColor: UIColor? {
didSet { get {
backgroundColorView.backgroundColor = backgroundColor return backgroundColorView.backgroundColor
}
set(value) {
backgroundColorView.backgroundColor = value
} }
} }
/** /**
:name: pulseColor :name: pulseColor
*/ */
public var pulseColor: UIColor? public var pulseColor: UIColor? = MaterialTheme.white.color
/** /**
:name: init :name: init
...@@ -98,26 +101,38 @@ public class MaterialButton : UIButton { ...@@ -98,26 +101,38 @@ public class MaterialButton : UIButton {
final public override func drawRect(rect: CGRect) { final public override func drawRect(rect: CGRect) {
prepareContext(rect) prepareContext(rect)
prepareButton() prepareButton()
}
//
// :name: prepareView
//
internal func prepareView() {
setTranslatesAutoresizingMaskIntoConstraints(false)
prepareBackgroundColorView() prepareBackgroundColorView()
} }
// //
// :name: prepareButton // :name: prepareButton
// //
internal func prepareButton() { internal func prepareButton() {}
backgroundColorView.frame = bounds
//
// :name: prepareShadow
//
internal func prepareShadow() {
layer.shadowColor = MaterialTheme.black.color.CGColor
layer.shadowOffset = CGSizeMake(0.5, 0.5)
layer.shadowOpacity = 0.5
layer.shadowRadius = 5
} }
// //
// :name: pulseBegan // :name: pulseBegan
// //
internal func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) { internal func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch pulseView = UIView(frame: CGRectMake(0, 0, bounds.height, bounds.height))
let touchLocation = touch.locationInView(self)
pulseView = UIView()
pulseView!.frame = CGRectMake(0, 0, bounds.height, bounds.height)
pulseView!.layer.cornerRadius = bounds.height / 2 pulseView!.layer.cornerRadius = bounds.height / 2
pulseView!.center = touchLocation pulseView!.center = (touches.first as! UITouch).locationInView(self)
pulseView!.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5) pulseView!.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!) backgroundColorView.addSubview(pulseView!)
} }
...@@ -137,13 +152,15 @@ public class MaterialButton : UIButton { ...@@ -137,13 +152,15 @@ public class MaterialButton : UIButton {
} }
// //
// :name: prepareShadow // :name: prepareContext
// //
internal func prepareShadow() { private func prepareContext(rect: CGRect) {
layer.shadowOffset = CGSizeMake(1, 1) let context = UIGraphicsGetCurrentContext()
layer.shadowColor = UIColor.blackColor().CGColor CGContextSaveGState(context);
layer.shadowOpacity = 0.5 CGContextAddEllipseInRect(context, rect)
layer.shadowRadius = 5 CGContextSetFillColorWithColor(context, MaterialTheme.clear.color.CGColor)
CGContextFillPath(context)
CGContextRestoreGState(context);
} }
// //
...@@ -152,29 +169,12 @@ public class MaterialButton : UIButton { ...@@ -152,29 +169,12 @@ public class MaterialButton : UIButton {
// We need this view so we can use the masksToBounds // We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button // so the pulse doesn't animate off the button
private func prepareBackgroundColorView() { private func prepareBackgroundColorView() {
backgroundColorView.setTranslatesAutoresizingMaskIntoConstraints(false)
backgroundColorView.layer.masksToBounds = true backgroundColorView.layer.masksToBounds = true
backgroundColorView.clipsToBounds = true backgroundColorView.clipsToBounds = true
backgroundColorView.userInteractionEnabled = false backgroundColorView.userInteractionEnabled = false
insertSubview(backgroundColorView, atIndex: 0) insertSubview(backgroundColorView, atIndex: 0)
} Layout.expandToParentSize(self, child: backgroundColorView)
//
// :name: prepareView
//
private func prepareView() {
setTranslatesAutoresizingMaskIntoConstraints(false)
}
//
// :name: prepareContext
//
private func prepareContext(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context);
CGContextAddEllipseInRect(context, rect)
CGContextSetFillColorWithColor(context, UIColor.clearColor().CGColor)
CGContextFillPath(context)
CGContextRestoreGState(context);
} }
// //
......
//
// 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 MaterialCard : UIView {
//
// :name: backgroundColorView
//
internal lazy var backgroundColorView: UIView = UIView()
//
// :name: pulseView
//
internal var pulseView: UIView?
/**
:name: backgroundColor
*/
public override var backgroundColor: UIColor? {
get {
return backgroundColorView.backgroundColor
}
set(value) {
backgroundColorView.backgroundColor = value
}
}
/**
:name: pulseColor
*/
public var pulseColor: UIColor = MaterialTheme.white.color
/**
:name: init
*/
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
/**
:name: init
*/
public required override init(frame: CGRect) {
super.init(frame: frame)
prepareView()
}
/**
:name: init
*/
public convenience init() {
self.init(frame: CGRectZero)
}
/**
:name: touchesBegan
*/
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
pulseBegan(touches, withEvent: event)
}
/**
:name: touchesEnded
*/
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
shrink()
pulseEnded(touches, withEvent: event)
}
/**
:name: touchesCancelled
*/
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
shrink()
pulseEnded(touches, withEvent: event)
}
//
// :name: prepareView
//
internal func prepareView() {
setTranslatesAutoresizingMaskIntoConstraints(false)
prepareBackgroundColorView()
prepareCard()
}
//
// :name: prepareCard
//
internal func prepareCard() {}
//
// :name: prepareShadow
//
internal func prepareShadow() {
layer.shadowColor = MaterialTheme.black.color.CGColor
layer.shadowOffset = CGSizeMake(0.5, 0.5)
layer.shadowOpacity = 0.5
layer.shadowRadius = 5
layer.cornerRadius = 2
}
//
// :name: layoutSubviews
//
public override func layoutSubviews() {
super.layoutSubviews()
layer.shadowPath = UIBezierPath(rect: bounds).CGPath
}
//
// :name: pulseBegan
//
internal func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
let width: CGFloat = bounds.size.width / 3
pulseView = UIView(frame: CGRectMake(0, 0, width, width))
pulseView!.layer.cornerRadius = width / 2
pulseView!.center = (touches.first as! UITouch).locationInView(self)
pulseView!.backgroundColor = pulseColor.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
self.transform = CGAffineTransformMakeScale(1.05, 1.05)
}, completion: nil)
}
//
// :name: pulseEnded
//
internal func pulseEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
UIView.animateWithDuration(0.3,
animations: { _ in
self.pulseView?.alpha = 0
}
) { _ in
self.pulseView?.removeFromSuperview()
self.pulseView = nil
}
}
//
// :name: prepareBackgroundColorView
//
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
private func prepareBackgroundColorView() {
backgroundColorView.setTranslatesAutoresizingMaskIntoConstraints(false)
backgroundColorView.layer.cornerRadius = 2
backgroundColorView.layer.masksToBounds = true
backgroundColorView.clipsToBounds = true
backgroundColorView.userInteractionEnabled = false
insertSubview(backgroundColorView, atIndex: 0)
Layout.expandToParentSize(self, child: backgroundColorView)
}
//
// :name: shrink
//
private func shrink() {
UIView.animateWithDuration(0.3,
delay: 0,
usingSpringWithDamping: 0.2,
initialSpringVelocity: 10,
options: nil,
animations: {
self.transform = CGAffineTransformIdentity
},
completion: nil
)
}
}
//
// 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 MaterialPulseView : MaterialView {
internal lazy var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
public var backgroundColorView: UIView?
public var pulseView: UIView?
public var color: UIColor?
public var pulseColor: UIColor?
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}
public required override init(frame: CGRect) {
super.init(frame: frame)
initialize()
}
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
pulseTouches(touches)
}
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
shrink()
removePulse()
}
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
shrink()
removePulse()
}
internal func initialize() {
setupSelf()
setupLayer()
setupBackgroundColorView()
constrainSubviews()
}
internal func constrainSubviews() {
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[backgroundColorView]|", options: nil, metrics: nil, views: views))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[backgroundColorView]|", options: nil, metrics: nil, views: views))
}
private func setupSelf() {
color = UIColor.clearColor()
pulseColor = UIColor.whiteColor()
setTranslatesAutoresizingMaskIntoConstraints(false)
backgroundColor = UIColor(red: 66.0/255.0, green: 91.0/255.0, blue: 103.0/255.0, alpha: 1.0)
}
private func setupLayer() {
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOffset = CGSizeMake(0.5, 0.5)
layer.shadowRadius = 5.0
layer.shadowOpacity = 0.4
layer.cornerRadius = 2.0
}
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
private func setupBackgroundColorView() {
backgroundColorView = UIView()
backgroundColorView?.userInteractionEnabled = false
backgroundColorView!.setTranslatesAutoresizingMaskIntoConstraints(false)
backgroundColorView!.layer.cornerRadius = 2.0
backgroundColorView!.backgroundColor = color
backgroundColorView!.layer.masksToBounds = true
addSubview(backgroundColorView!)
views["backgroundColorView"] = backgroundColorView
}
private func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self)
pulseView = UIView()
pulseView?.setTranslatesAutoresizingMaskIntoConstraints(false)
var width = bounds.size.width / 3.0
pulseView!.frame = CGRectMake(0, 0, width, width)
pulseView!.layer.cornerRadius = width / 2.0
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.1)
backgroundColorView!.addSubview(pulseView!)
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
self.transform = CGAffineTransformMakeScale(1.05, 1.05)
}, completion: nil)
}
private func shrink() {
UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: nil, animations: {
self.transform = CGAffineTransformIdentity
}, completion: nil)
}
private func removePulse() {
UIView.animateWithDuration(0.3, animations: { () -> Void in
self.pulseView?.alpha = 0.0
}) { (finished) -> Void in
self.pulseView?.removeFromSuperview()
self.pulseView = nil
}
}
}
//
// 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 MaterialView : UIView {
/**
:name: topLeft
*/
public func topLeft(child: UIView, top: CGFloat, left: CGFloat) {
Layout.alignFromTopLeft(self, child: child, top: top, left: left)
}
/**
:name: topRight
*/
public func topRight(child: UIView, top: CGFloat, right: CGFloat) {
Layout.alignFromTopRight(self, child: child, top: top, right: right)
}
/**
:name: bottomLeft
*/
public func bottomLeft(child: UIView, bottom: CGFloat, left: CGFloat) {
Layout.alignFromBottomLeft(self, child: child, bottom: bottom, left: left)
}
/**
:name: bottomRight
*/
public func bottomRight(child: UIView, bottom: CGFloat, right: CGFloat) {
Layout.alignFromBottomRight(self, child: child, bottom: bottom, right: right)
}
}
//
// 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 MaterialViewController : UIViewController {
/**
:name: topLeft
*/
public func topLeft(child: UIView, top: CGFloat, left: CGFloat) {
Layout.alignFromTopLeft(view, child: child, top: top, left: left)
}
/**
:name: topRight
*/
public func topRight(child: UIView, top: CGFloat, right: CGFloat) {
Layout.alignFromTopRight(view, child: child, top: top, right: right)
}
/**
:name: bottomLeft
*/
public func bottomLeft(child: UIView, bottom: CGFloat, left: CGFloat) {
Layout.alignFromBottomLeft(view, child: child, bottom: bottom, left: left)
}
/**
:name: bottomRight
*/
public func bottomRight(child: UIView, bottom: CGFloat, right: CGFloat) {
Layout.alignFromBottomRight(view, child: child, bottom: bottom, right: right)
}
}
...@@ -22,12 +22,19 @@ public class RaisedButton : MaterialButton { ...@@ -22,12 +22,19 @@ public class RaisedButton : MaterialButton {
// //
// :name: prepareButton // :name: prepareButton
// //
internal override func prepareButton() { internal override func prepareView() {
super.prepareView()
setTitleColor(MaterialTheme.white.color, forState: .Normal)
backgroundColor = MaterialTheme.indigo.darken1
contentEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 20)
}
//
// :name: prepareButton
//
internal override func prepareButton() {
super.prepareButton() super.prepareButton()
prepareShadow() prepareShadow()
setTitleColor(UIColor.whiteColor(), forState: .Normal)
pulseColor = .whiteColor()
backgroundColor = .purpleColor()
backgroundColorView.layer.cornerRadius = 3 backgroundColorView.layer.cornerRadius = 3
} }
...@@ -37,8 +44,8 @@ public class RaisedButton : MaterialButton { ...@@ -37,8 +44,8 @@ public class RaisedButton : MaterialButton {
internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) { internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.pulseBegan(touches, withEvent: event) super.pulseBegan(touches, withEvent: event)
UIView.animateWithDuration(0.3, animations: { UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10) self.pulseView!.transform = CGAffineTransformMakeScale(4, 4)
self.transform = CGAffineTransformMakeScale(1.05, 1.1) self.transform = CGAffineTransformMakeScale(1.05, 1.05)
}) })
} }
} }
......
// //
// Roboto.swift // Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
// MaterialKit
// //
// Created by Adam Dahan on 2015-08-22. // This program is free software: you can redistribute it and/or modify
// Copyright (c) 2015 GraphKit Inc. All rights reserved. // 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 import UIKit
......
...@@ -67,7 +67,7 @@ public protocol SideNavDelegate { ...@@ -67,7 +67,7 @@ public protocol SideNavDelegate {
} }
@objc(SideNavController) @objc(SideNavController)
public class SideNavController: MaterialViewController, UIGestureRecognizerDelegate { public class SideNavController: UIViewController, UIGestureRecognizerDelegate {
/** /**
:name: options :name: options
*/ */
...@@ -76,12 +76,12 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -76,12 +76,12 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
public static var shadowRadius: CGFloat = 0 public static var shadowRadius: CGFloat = 0
public static var shadowOffset: CGSize = CGSizeZero public static var shadowOffset: CGSize = CGSizeZero
public static var contentViewScale: CGFloat = 1 public static var contentViewScale: CGFloat = 1
public static var contentViewOpacity: CGFloat = 0.4 public static var contentViewOpacity: CGFloat = 0.5
public static var hideStatusBar: Bool = true public static var hideStatusBar: Bool = true
public static var pointOfNoReturnWidth: CGFloat = 48 public static var horizontalThreshold: CGFloat = 48
public static var pointOfNoReturnheight: CGFloat = 48 public static var verticalThreshold: CGFloat = 48
public static var backdropViewContainerBackgroundColor: UIColor = .blackColor() public static var backdropBackgroundColor: UIColor = MaterialTheme.black.color
public static var animationDuration: CGFloat = 0.5 public static var animationDuration: CGFloat = 0.3
public static var leftBezelWidth: CGFloat = 16 public static var leftBezelWidth: CGFloat = 16
public static var leftViewContainerWidth: CGFloat = 240 public static var leftViewContainerWidth: CGFloat = 240
public static var leftPanFromBezel: Bool = true public static var leftPanFromBezel: Bool = true
...@@ -689,7 +689,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -689,7 +689,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
} else { } else {
c.point = gesture.velocityInView(gesture.view) c.point = gesture.velocityInView(gesture.view)
let x: CGFloat = c.point.x >= 1000 || c.point.x <= -1000 ? c.point.x : 0 let x: CGFloat = c.point.x >= 1000 || c.point.x <= -1000 ? c.point.x : 0
c.state = vc.frame.origin.x <= CGFloat(floor(leftOriginX)) + options.pointOfNoReturnWidth || c.point.x <= -1000 ? .Closed : .Opened c.state = vc.frame.origin.x <= CGFloat(floor(leftOriginX)) + options.horizontalThreshold || c.point.x <= -1000 ? .Closed : .Opened
if .Closed == c.state { if .Closed == c.state {
closeLeftViewContainer(velocity: x) closeLeftViewContainer(velocity: x)
} else { } else {
...@@ -738,7 +738,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -738,7 +738,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
} else { } else {
c.point = gesture.velocityInView(gesture.view) c.point = gesture.velocityInView(gesture.view)
let x: CGFloat = c.point.x <= -1000 || c.point.x >= 1000 ? c.point.x : 0 let x: CGFloat = c.point.x <= -1000 || c.point.x >= 1000 ? c.point.x : 0
c.state = vc.frame.origin.x >= CGFloat(floor(rightOriginX) - options.pointOfNoReturnWidth) || c.point.x >= 1000 ? .Closed : .Opened c.state = vc.frame.origin.x >= CGFloat(floor(rightOriginX) - options.horizontalThreshold) || c.point.x >= 1000 ? .Closed : .Opened
if .Closed == c.state { if .Closed == c.state {
closeRightViewContainer(velocity: x) closeRightViewContainer(velocity: x)
} else { } else {
...@@ -795,7 +795,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -795,7 +795,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
if let c = bottomContainer { if let c = bottomContainer {
c.point = gesture.velocityInView(gesture.view) c.point = gesture.velocityInView(gesture.view)
let y: CGFloat = c.point.y <= -1000 || c.point.y >= 1000 ? c.point.y : 0 let y: CGFloat = c.point.y <= -1000 || c.point.y >= 1000 ? c.point.y : 0
c.state = vc.frame.origin.y >= CGFloat(floor(bottomOriginY) - options.pointOfNoReturnheight) || c.point.y >= 1000 ? .Closed : .Opened c.state = vc.frame.origin.y >= CGFloat(floor(bottomOriginY) - options.verticalThreshold) || c.point.y >= 1000 ? .Closed : .Opened
if .Closed == c.state { if .Closed == c.state {
closeBottomViewContainer(velocity: y) closeBottomViewContainer(velocity: y)
} else { } else {
...@@ -947,7 +947,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -947,7 +947,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
// //
private func prepareBackdropContainer() { private func prepareBackdropContainer() {
backdropViewContainer = UIView(frame: view.bounds) backdropViewContainer = UIView(frame: view.bounds)
backdropViewContainer!.backgroundColor = options.backdropViewContainerBackgroundColor backdropViewContainer!.backgroundColor = options.backdropBackgroundColor
backdropViewContainer!.autoresizingMask = .FlexibleHeight | .FlexibleWidth backdropViewContainer!.autoresizingMask = .FlexibleHeight | .FlexibleWidth
backdropViewContainer!.layer.opacity = 0 backdropViewContainer!.layer.opacity = 0
view.addSubview(backdropViewContainer!) view.addSubview(backdropViewContainer!)
...@@ -1014,9 +1014,10 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -1014,9 +1014,10 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
private func prepareContainedViewController(inout viewContainer: UIView?, inout viewController: UIViewController?) { private func prepareContainedViewController(inout viewContainer: UIView?, inout viewController: UIViewController?) {
if let vc = viewController { if let vc = viewController {
if let c = viewContainer { if let c = viewContainer {
vc.view.setTranslatesAutoresizingMaskIntoConstraints(false)
addChildViewController(vc) addChildViewController(vc)
vc.view.frame = c.bounds
c.addSubview(vc.view) c.addSubview(vc.view)
Layout.expandToParentSize(c, child: vc.view)
vc.didMoveToParentViewController(self) vc.didMoveToParentViewController(self)
} }
} }
......
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