Commit 657394ba by Daniel Dahan

added IconButton

parent 1e131e83
......@@ -41,22 +41,27 @@ class AppNavigationController: NavigationController {
prepareNavigationBar()
}
/**
Uncomment the code to set a statusBar that is colored, different
from the NavigationBar. Note, if using the .CenterRadialBeyondBounds
pulseAnimation value, it will cover the animation radial effect.
*/
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
statusBarView?.hidden = MaterialDevice.statusBarHidden
// statusBarView?.hidden = MaterialDevice.statusBarHidden
}
/// Prepares the statusBarView
private func prepareStatusBarView() {
statusBarView = MaterialView()
statusBarView!.backgroundColor = MaterialColor.blue.darken2
view.addSubview(statusBarView!)
statusBarView!.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: statusBarView!)
MaterialLayout.alignToParentHorizontally(view, child: statusBarView!)
MaterialLayout.height(view, child: statusBarView!, height: 20)
// statusBarView = MaterialView()
// statusBarView!.backgroundColor = MaterialColor.blue.darken2
// view.addSubview(statusBarView!)
// statusBarView!.translatesAutoresizingMaskIntoConstraints = false
// MaterialLayout.alignFromTop(view, child: statusBarView!)
// MaterialLayout.alignToParentHorizontally(view, child: statusBarView!)
// MaterialLayout.height(view, child: statusBarView!, height: 20)
}
/// Prepares the navigationBar
......
......@@ -77,7 +77,7 @@ class AppSearchBarController: SearchBarController {
var image: UIImage? = MaterialIcon.cm.arrowBack
// Back button.
let backButton: FlatButton = FlatButton()
let backButton: IconButton = IconButton()
backButton.pulseColor = MaterialColor.grey.base
backButton.tintColor = MaterialColor.grey.darken4
backButton.setImage(image, forState: .Normal)
......@@ -86,7 +86,7 @@ class AppSearchBarController: SearchBarController {
// More button.
image = MaterialIcon.cm.moreHorizontal
let moreButton: FlatButton = FlatButton()
let moreButton: IconButton = IconButton()
moreButton.pulseColor = MaterialColor.grey.base
moreButton.tintColor = MaterialColor.grey.darken4
moreButton.setImage(image, forState: .Normal)
......
......@@ -45,7 +45,7 @@ class ItemViewController: UIViewController {
private var detailLabel: UILabel!
/// NavigationBar share button.
private var shareButton: FlatButton!
private var shareButton: IconButton!
/// MaterialScrollView.
private var scrollView: UIScrollView!
......@@ -120,7 +120,7 @@ class ItemViewController: UIViewController {
/// Prepares the shareButton.
private func prepareShareButton() {
let image: UIImage? = MaterialIcon.cm.share
shareButton = FlatButton()
shareButton = IconButton()
shareButton.pulseColor = MaterialColor.white
shareButton.setImage(image, forState: .Normal)
shareButton.setImage(image, forState: .Highlighted)
......@@ -145,7 +145,7 @@ class ItemViewController: UIViewController {
imageCardView = ImageCardView()
imageCardView.pulseColor = nil
imageCardView.pulseAnimation = .None
imageCardView.divider = false
imageCardView.depth = .None
imageCardView.contentInsetPreset = .Square3
......
......@@ -39,13 +39,13 @@ class RecipesViewController: UIViewController {
private var titleLabel: UILabel!
/// NavigationBar menu button.
private var menuButton: FlatButton!
private var menuButton: IconButton!
/// NavigationBar switch control.
private var switchControl: MaterialSwitch!
/// NavigationBar search button.
private var searchButton: FlatButton!
private var searchButton: IconButton!
/// A tableView used to display items.
private var tableView: UITableView!
......@@ -229,7 +229,7 @@ class RecipesViewController: UIViewController {
/// Prepares the menuButton.
private func prepareMenuButton() {
let image: UIImage? = MaterialIcon.cm.menu
menuButton = FlatButton()
menuButton = IconButton()
menuButton.pulseColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted)
......@@ -244,7 +244,7 @@ class RecipesViewController: UIViewController {
/// Prepares the searchButton.
private func prepareSearchButton() {
let image: UIImage? = MaterialIcon.cm.search
searchButton = FlatButton()
searchButton = IconButton()
searchButton.pulseColor = MaterialColor.white
searchButton.setImage(image, forState: .Normal)
searchButton.setImage(image, forState: .Highlighted)
......
......@@ -35,10 +35,10 @@ import AVFoundation
class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDelegate {
lazy var captureView: CaptureView = CaptureView()
lazy var toolbar: Toolbar = Toolbar()
lazy var cameraButton: FlatButton = FlatButton()
lazy var videoButton: FlatButton = FlatButton()
lazy var switchCamerasButton: FlatButton = FlatButton()
lazy var flashButton: FlatButton = FlatButton()
lazy var cameraButton: IconButton = IconButton()
lazy var videoButton: IconButton = IconButton()
lazy var switchCamerasButton: IconButton = IconButton()
lazy var flashButton: IconButton = IconButton()
lazy var captureButton: FabButton = FabButton()
override func viewDidLoad() {
......
......@@ -110,7 +110,7 @@ class ViewController: UIViewController {
// Share button.
let img1: UIImage? = MaterialIcon.cm.share
let btn1: FlatButton = FlatButton()
let btn1: IconButton = IconButton()
btn1.pulseColor = MaterialColor.white
btn1.tintColor = MaterialColor.white
btn1.setImage(img1, forState: .Normal)
......@@ -151,7 +151,7 @@ class ViewController: UIViewController {
// Share button.
let img1: UIImage? = MaterialIcon.cm.share
let btn1: FlatButton = FlatButton()
let btn1: IconButton = IconButton()
btn1.pulseColor = MaterialColor.white
btn1.tintColor = MaterialColor.white
btn1.setImage(img1, forState: .Normal)
......@@ -175,7 +175,7 @@ class ViewController: UIViewController {
// Search button.
let img1: UIImage? = MaterialIcon.cm.search
let btn1: FlatButton = FlatButton()
let btn1: IconButton = IconButton()
btn1.pulseColor = MaterialColor.white
btn1.tintColor = MaterialColor.white
btn1.setImage(img1, forState: .Normal)
......
......@@ -57,7 +57,7 @@ class ViewController: UIViewController {
/// Prepares the Horizontal GridView example.
private func prepareHorizontalGridViewExample() {
var image: UIImage? = UIImage(named: "ic_flash_auto_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn1: FlatButton = FlatButton()
let btn1: IconButton = IconButton()
btn1.pulseColor = MaterialColor.blueGrey.darken4
btn1.tintColor = MaterialColor.blueGrey.darken4
btn1.backgroundColor = MaterialColor.grey.lighten3
......@@ -66,7 +66,7 @@ class ViewController: UIViewController {
view.addSubview(btn1)
image = UIImage(named: "ic_flash_off_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn2: FlatButton = FlatButton()
let btn2: IconButton = IconButton()
btn2.pulseColor = MaterialColor.blueGrey.darken4
btn2.tintColor = MaterialColor.blueGrey.darken4
btn2.backgroundColor = MaterialColor.grey.lighten3
......@@ -75,7 +75,7 @@ class ViewController: UIViewController {
view.addSubview(btn2)
image = UIImage(named: "ic_flash_on_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn3: FlatButton = FlatButton()
let btn3: IconButton = IconButton()
btn3.pulseColor = MaterialColor.blueGrey.darken4
btn3.tintColor = MaterialColor.blueGrey.darken4
btn3.backgroundColor = MaterialColor.grey.lighten3
......@@ -106,7 +106,7 @@ class ViewController: UIViewController {
/// Prepares the Vertical GridView example.
private func prepareVerticalGridViewExample() {
var image: UIImage? = UIImage(named: "ic_flash_auto_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn1: FlatButton = FlatButton()
let btn1: IconButton = IconButton()
btn1.pulseColor = MaterialColor.blueGrey.darken4
btn1.tintColor = MaterialColor.blueGrey.darken4
btn1.backgroundColor = MaterialColor.grey.lighten3
......@@ -115,7 +115,7 @@ class ViewController: UIViewController {
view.addSubview(btn1)
image = UIImage(named: "ic_flash_off_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn2: FlatButton = FlatButton()
let btn2: IconButton = IconButton()
btn2.pulseColor = MaterialColor.blueGrey.darken4
btn2.tintColor = MaterialColor.blueGrey.darken4
btn2.backgroundColor = MaterialColor.grey.lighten3
......@@ -124,7 +124,7 @@ class ViewController: UIViewController {
view.addSubview(btn2)
image = UIImage(named: "ic_flash_on_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn3: FlatButton = FlatButton()
let btn3: IconButton = IconButton()
btn3.pulseColor = MaterialColor.blueGrey.darken4
btn3.tintColor = MaterialColor.blueGrey.darken4
btn3.backgroundColor = MaterialColor.grey.lighten3
......@@ -203,7 +203,7 @@ class ViewController: UIViewController {
contentView.addSubview(titleLabel)
image = MaterialIcon.cm.moreVertical
let moreButton: FlatButton = FlatButton()
let moreButton: IconButton = IconButton()
moreButton.contentEdgeInsetsPreset = .None
moreButton.pulseColor = MaterialColor.blueGrey.darken4
moreButton.tintColor = MaterialColor.blueGrey.darken4
......@@ -228,7 +228,7 @@ class ViewController: UIViewController {
contentView.addSubview(alarmLabel)
image = UIImage(named: "ic_alarm_white")?.imageWithRenderingMode(.AlwaysTemplate)
let alarmButton: FlatButton = FlatButton()
let alarmButton: IconButton = IconButton()
alarmButton.contentEdgeInsetsPreset = .None
alarmButton.pulseColor = MaterialColor.blueGrey.darken4
alarmButton.tintColor = MaterialColor.red.base
......@@ -300,7 +300,7 @@ class ViewController: UIViewController {
contentView.addSubview(titleLabel)
image = MaterialIcon.cm.moreVertical
let moreButton: FlatButton = FlatButton()
let moreButton: IconButton = IconButton()
moreButton.contentEdgeInsetsPreset = .None
moreButton.pulseColor = MaterialColor.blueGrey.darken4
moreButton.tintColor = MaterialColor.blueGrey.darken4
......@@ -325,7 +325,7 @@ class ViewController: UIViewController {
contentView.addSubview(alarmLabel)
image = UIImage(named: "ic_alarm_white")?.imageWithRenderingMode(.AlwaysTemplate)
let alarmButton: FlatButton = FlatButton()
let alarmButton: IconButton = IconButton()
alarmButton.contentEdgeInsetsPreset = .None
alarmButton.pulseColor = MaterialColor.blueGrey.darken4
alarmButton.tintColor = MaterialColor.red.base
......@@ -409,7 +409,7 @@ class ViewController: UIViewController {
contentView.addSubview(titleLabel)
image = MaterialIcon.cm.moreHorizontal
let moreButton: FlatButton = FlatButton()
let moreButton: IconButton = IconButton()
moreButton.contentEdgeInsetsPreset = .None
moreButton.pulseColor = MaterialColor.blueGrey.darken4
moreButton.tintColor = MaterialColor.blueGrey.darken4
......@@ -434,7 +434,7 @@ class ViewController: UIViewController {
contentView.addSubview(alarmLabel)
image = UIImage(named: "ic_alarm_white")?.imageWithRenderingMode(.AlwaysTemplate)
let alarmButton: FlatButton = FlatButton()
let alarmButton: IconButton = IconButton()
alarmButton.contentEdgeInsetsPreset = .None
alarmButton.pulseColor = MaterialColor.blueGrey.darken4
alarmButton.tintColor = MaterialColor.red.base
......
......@@ -107,7 +107,7 @@ class ViewController: UIViewController {
// Star button.
let img1: UIImage? = MaterialIcon.cm.star
let btn1: FlatButton = FlatButton()
let btn1: IconButton = IconButton()
btn1.pulseColor = MaterialColor.blueGrey.lighten1
btn1.tintColor = MaterialColor.blueGrey.darken3
btn1.setImage(img1, forState: .Normal)
......@@ -115,7 +115,7 @@ class ViewController: UIViewController {
// Library button.
let img2: UIImage? = MaterialIcon.cm.audioLibrary
let btn2: FlatButton = FlatButton()
let btn2: IconButton = IconButton()
btn2.pulseColor = MaterialColor.blueGrey.lighten1
btn2.tintColor = MaterialColor.blueGrey.darken3
btn2.setImage(img2, forState: .Normal)
......@@ -123,7 +123,7 @@ class ViewController: UIViewController {
// Share button.
let img3: UIImage? = MaterialIcon.share
let btn3: FlatButton = FlatButton()
let btn3: IconButton = IconButton()
btn3.pulseColor = MaterialColor.blueGrey.lighten1
btn3.tintColor = MaterialColor.blueGrey.darken3
btn3.setImage(img3, forState: .Normal)
......
......@@ -59,7 +59,7 @@ class ViewController: UIViewController {
pulseView.shape = .Square
pulseView.depth = .Depth1
pulseView.cornerRadiusPreset = .Radius3
// pulseView.pulseAnimation = .CenterWithBacking // Set a different type of pulse animation.
pulseView.pulseAnimation = .CenterRadialBeyondBounds
// Add pulseView to UIViewController.
view.addSubview(pulseView)
......@@ -69,11 +69,11 @@ class ViewController: UIViewController {
// pulseView.pulse(CGPointMake(30, 30))
// }
pulseView.animate(MaterialAnimation.animationGroup([
MaterialAnimation.rotate(rotation: 0.5),
MaterialAnimation.rotateX(rotation: 2),
MaterialAnimation.translateY(200)
], duration: 4))
// pulseView.animate(MaterialAnimation.animationGroup([
// MaterialAnimation.rotate(rotation: 0.5),
// MaterialAnimation.rotateX(rotation: 2),
// MaterialAnimation.translateY(200)
// ], duration: 4))
}
}
......@@ -57,7 +57,7 @@ class ViewController: UIViewController {
var image: UIImage? = MaterialIcon.cm.arrowBack
// Back button.
let backButton: FlatButton = FlatButton()
let backButton: IconButton = IconButton()
backButton.pulseColor = MaterialColor.grey.base
backButton.tintColor = MaterialColor.grey.darken4
backButton.setImage(image, forState: .Normal)
......@@ -68,7 +68,7 @@ class ViewController: UIViewController {
// More button.
image = MaterialIcon.cm.moreHorizontal
let moreButton: FlatButton = FlatButton()
let moreButton: IconButton = IconButton()
moreButton.pulseColor = MaterialColor.grey.base
moreButton.tintColor = MaterialColor.grey.darken4
moreButton.setImage(image, forState: .Normal)
......
......@@ -79,8 +79,7 @@ class AppSearchBarController: SearchBarController {
var image: UIImage? = MaterialIcon.cm.arrowBack
// Back button.
let backButton: FlatButton = FlatButton()
backButton.pulseColor = nil
let backButton: IconButton = IconButton()
backButton.tintColor = MaterialColor.blueGrey.darken4
backButton.setImage(image, forState: .Normal)
backButton.setImage(image, forState: .Highlighted)
......@@ -88,8 +87,7 @@ class AppSearchBarController: SearchBarController {
// More button.
image = MaterialIcon.cm.moreHorizontal
let moreButton: FlatButton = FlatButton()
moreButton.pulseColor = nil
let moreButton: IconButton = IconButton()
moreButton.tintColor = MaterialColor.blueGrey.darken4
moreButton.setImage(image, forState: .Normal)
moreButton.setImage(image, forState: .Highlighted)
......
......@@ -105,8 +105,8 @@ class ViewController: UIViewController {
let closeButton: FlatButton = FlatButton()
closeButton.setTitle("Close", forState: .Normal)
let image: UIImage? = UIImage(named: "ic_settings")?.imageWithRenderingMode(.AlwaysTemplate)
let settingButton: FlatButton = FlatButton()
let image: UIImage? = MaterialIcon.cm.settings
let settingButton: IconButton = IconButton()
settingButton.tintColor = MaterialColor.blue.accent3
settingButton.setImage(image, forState: .Normal)
settingButton.setImage(image, forState: .Highlighted)
......
......@@ -92,7 +92,6 @@ class ViewController: UIViewController, TextFieldDelegate {
nameField.detail = "Your given name"
nameField.textAlignment = .Center
nameField.clearButtonMode = .WhileEditing
nameField.dividerActiveColor = MaterialColor.green.base
nameField.delegate = self
// The translatesAutoresizingMaskIntoConstraints property must be set to enable AutoLayout correctly.
......@@ -110,7 +109,7 @@ class ViewController: UIViewController, TextFieldDelegate {
emailField = TextField(frame: CGRectMake(40, 120, view.bounds.width - 80, 32))
emailField.placeholder = "Email"
emailField.detail = "Error, incorrect email"
emailField.enableClearFlatButton = true
emailField.enableClearIconButton = true
emailField.delegate = self
emailField.placeholderColor = MaterialColor.amber.darken4
......@@ -127,11 +126,11 @@ class ViewController: UIViewController, TextFieldDelegate {
passwordField.placeholder = "Password"
passwordField.detail = "At least 8 characters"
passwordField.clearButtonMode = .WhileEditing
passwordField.enableVisibilityFlatButton = true
passwordField.enableVisibilityIconButton = true
passwordField.delegate = self
// Setting the visibilityFlatButton color.
passwordField.visibilityFlatButton?.tintColor = MaterialColor.green.base.colorWithAlphaComponent(passwordField.secureTextEntry ? 0.38 : 0.54)
passwordField.visibilityIconButton?.tintColor = MaterialColor.green.base.colorWithAlphaComponent(passwordField.secureTextEntry ? 0.38 : 0.54)
// The translatesAutoresizingMaskIntoConstraints property must be set to enable AutoLayout correctly.
passwordField.translatesAutoresizingMaskIntoConstraints = false
......
......@@ -71,7 +71,7 @@ class ViewController: UIViewController {
var image: UIImage? = MaterialIcon.cm.menu
// Menu button.
let menuButton: FlatButton = FlatButton()
let menuButton: IconButton = IconButton()
menuButton.pulseColor = MaterialColor.white
menuButton.tintColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal)
......@@ -82,7 +82,7 @@ class ViewController: UIViewController {
// Search button.
image = MaterialIcon.cm.search
let searchButton: FlatButton = FlatButton()
let searchButton: IconButton = IconButton()
searchButton.pulseColor = MaterialColor.white
searchButton.tintColor = MaterialColor.white
searchButton.setImage(image, forState: .Normal)
......
......@@ -94,8 +94,7 @@ class AppToolbarController: ToolbarController {
var image: UIImage? = MaterialIcon.cm.menu
// Menu button.
let menuButton: FlatButton = FlatButton()
menuButton.pulseColor = nil
let menuButton: IconButton = IconButton()
menuButton.tintColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted)
......@@ -107,8 +106,7 @@ class AppToolbarController: ToolbarController {
// Search button.
image = MaterialIcon.cm.search
let searchButton: FlatButton = FlatButton()
searchButton.pulseColor = nil
let searchButton: IconButton = IconButton()
searchButton.tintColor = MaterialColor.white
searchButton.setImage(image, forState: .Normal)
searchButton.setImage(image, forState: .Highlighted)
......
......@@ -61,7 +61,7 @@ class ViewController: UIViewController {
// Star button.
let img1: UIImage? = MaterialIcon.cm.star
let btn1: FlatButton = FlatButton()
let btn1: IconButton = IconButton()
btn1.pulseColor = MaterialColor.blueGrey.lighten1
btn1.tintColor = MaterialColor.blueGrey.lighten1
btn1.setImage(img1, forState: .Normal)
......@@ -69,7 +69,7 @@ class ViewController: UIViewController {
// Bell button.
let img2: UIImage? = MaterialIcon.cm.bell
let btn2: FlatButton = FlatButton()
let btn2: IconButton = IconButton()
btn2.pulseColor = MaterialColor.blueGrey.lighten1
btn2.tintColor = MaterialColor.blueGrey.lighten1
btn2.setImage(img2, forState: .Normal)
......@@ -77,7 +77,7 @@ class ViewController: UIViewController {
// Share button.
let img3: UIImage? = MaterialIcon.cm.share
let btn3: FlatButton = FlatButton()
let btn3: IconButton = IconButton()
btn3.pulseColor = MaterialColor.blueGrey.lighten1
btn3.tintColor = MaterialColor.blueGrey.lighten1
btn3.setImage(img3, forState: .Normal)
......
......@@ -95,7 +95,7 @@ class ViewController: UIViewController {
// Menu button.
let img1: UIImage? = MaterialIcon.cm.menu
let btn1: FlatButton = FlatButton()
let btn1: IconButton = IconButton()
btn1.pulseColor = MaterialColor.white
btn1.tintColor = MaterialColor.white
btn1.setImage(img1, forState: .Normal)
......@@ -103,7 +103,7 @@ class ViewController: UIViewController {
// Star button.
let img2: UIImage? = MaterialIcon.cm.star
let btn2: FlatButton = FlatButton()
let btn2: IconButton = IconButton()
btn2.pulseColor = MaterialColor.white
btn2.tintColor = MaterialColor.white
btn2.setImage(img2, forState: .Normal)
......@@ -111,7 +111,7 @@ class ViewController: UIViewController {
// Search button.
let img3: UIImage? = MaterialIcon.cm.search
let btn3: FlatButton = FlatButton()
let btn3: IconButton = IconButton()
btn3.pulseColor = MaterialColor.white
btn3.tintColor = MaterialColor.white
btn3.setImage(img3, forState: .Normal)
......
......@@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
96334EF61C8B84660083986B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96334EF51C8B84660083986B /* Assets.xcassets */; };
963832421B88DFD80015F710 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* Material.framework */; };
9658F2171CD6FA4700B902C1 /* IconButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9658F2161CD6FA4700B902C1 /* IconButton.swift */; };
9660161D1CB2ED6C00AAB661 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 966016131CB2ED6C00AAB661 /* Material.framework */; };
9660162A1CB2F04E00AAB661 /* Material.h in Headers */ = {isa = PBXBuildFile; fileRef = 96D88C091C1328D800B91418 /* Material.h */; settings = {ATTRIBUTES = (Public, ); }; };
9679CEAB1CC69E080021685B /* Material+UIImage+TintColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9679CEAA1CC69E080021685B /* Material+UIImage+TintColor.swift */; };
......@@ -196,6 +197,7 @@
963832361B88DFD80015F710 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Material.framework; sourceTree = BUILT_PRODUCTS_DIR; };
963832411B88DFD80015F710 /* Material.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Material.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
963832591B88E31A0015F710 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9658F2161CD6FA4700B902C1 /* IconButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IconButton.swift; sourceTree = "<group>"; };
966016131CB2ED6C00AAB661 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Material.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9660161C1CB2ED6C00AAB661 /* Material OSX Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Material OSX Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
967887881C9777CB0037F6C9 /* MaterialViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialViewTests.swift; sourceTree = "<group>"; };
......@@ -456,6 +458,7 @@
96BCB75F1CB40DC500C806FE /* FabButton.swift */,
96BCB7601CB40DC500C806FE /* FlatButton.swift */,
96BCB7931CB40DC500C806FE /* RaisedButton.swift */,
9658F2161CD6FA4700B902C1 /* IconButton.swift */,
);
name = Button;
sourceTree = "<group>";
......@@ -869,6 +872,7 @@
96BCB7C01CB40DC500C806FE /* MaterialDataSourceItem.swift in Sources */,
96BCB7AC1CB40DC500C806FE /* Material+Obj-C.swift in Sources */,
9679CEAB1CC69E080021685B /* Material+UIImage+TintColor.swift in Sources */,
9658F2171CD6FA4700B902C1 /* IconButton.swift in Sources */,
96BCB7BB1CB40DC500C806FE /* MaterialCollectionViewCell.swift in Sources */,
96BCB7CF1CB40DC500C806FE /* MaterialShape.swift in Sources */,
96BCB7DF1CB40DC500C806FE /* SearchBarController.swift in Sources */,
......
......@@ -126,6 +126,7 @@ public class BottomNavigationController : UITabBarController, UITabBarController
*/
public func prepareView() {
view.clipsToBounds = true
view.contentScaleFactor = MaterialDevice.scale
delegate = self
prepareTabBar()
}
......
......@@ -249,6 +249,7 @@ public class BottomTabBar : UITabBar {
*/
public func prepareView() {
depth = .Depth1
contentScaleFactor = MaterialDevice.scale
backgroundColor = MaterialColor.white
let image: UIImage? = UIImage.imageWithColor(MaterialColor.clear, size: CGSizeMake(1, 1))
shadowImage = image
......
......@@ -409,7 +409,6 @@ public class CardView : MaterialPulseView {
*/
public override func prepareView() {
super.prepareView()
pulseColor = MaterialColor.grey.lighten1
depth = .Depth1
dividerColor = MaterialColor.grey.lighten3
cornerRadiusPreset = .Radius1
......
......@@ -42,8 +42,9 @@ public class FabButton : MaterialButton {
super.prepareView()
depth = .Depth1
shape = .Circle
backgroundColor = MaterialColor.blue.base
pulseAnimation = .Center
pulseColor = MaterialColor.white
tintColor = MaterialColor.white
backgroundColor = MaterialColor.blue.base
}
}
\ 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 IconButton : MaterialButton {
/**
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 override func prepareView() {
super.prepareView()
cornerRadiusPreset = .Radius1
contentEdgeInsetsPreset = .WideRectangle3
pulseAnimation = .Center
}
}
\ No newline at end of file
......@@ -550,7 +550,6 @@ public class ImageCardView : MaterialPulseView {
*/
public override func prepareView() {
super.prepareView()
pulseColor = MaterialColor.grey.lighten1
depth = .Depth1
dividerColor = MaterialColor.grey.lighten3
cornerRadiusPreset = .Radius1
......
......@@ -50,13 +50,17 @@ public class MaterialButton : UIButton {
public private(set) lazy var pulseLayers: Array<CAShapeLayer> = Array<CAShapeLayer>()
/// The opacity value for the pulse animation.
@IBInspectable public var pulseOpacity: CGFloat = 0.12
@IBInspectable public var pulseOpacity: CGFloat = 0.25
/// The color of the pulse effect.
@IBInspectable public var pulseColor: UIColor?
@IBInspectable public var pulseColor: UIColor = MaterialColor.grey.base
/// The type of PulseAnimation.
public var pulseAnimation: PulseAnimation = .AtPointWithBacking
public var pulseAnimation: PulseAnimation = .AtPointWithBacking {
didSet {
visualLayer.masksToBounds = .CenterRadialBeyondBounds != pulseAnimation
}
}
/**
This property is the same as clipsToBounds. It crops any of the view's
......@@ -411,7 +415,7 @@ public class MaterialButton : UIButton {
}
MaterialAnimation.delay(0.35) { [weak self] in
if let s: MaterialButton = self {
MaterialAnimation.pulseContractAnimation(s.layer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
MaterialAnimation.pulseContractAnimation(s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
}
}
}
......@@ -435,7 +439,7 @@ public class MaterialButton : UIButton {
*/
public override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.pulseContractAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -446,7 +450,7 @@ public class MaterialButton : UIButton {
*/
public override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
super.touchesCancelled(touches, withEvent: event)
MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.pulseContractAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -457,7 +461,6 @@ public class MaterialButton : UIButton {
when subclassing.
*/
public func prepareView() {
pulseColor = MaterialColor.black
contentScaleFactor = MaterialDevice.scale
prepareVisualLayer()
}
......
......@@ -118,6 +118,7 @@ public class MaterialCollectionView : UICollectionView {
when subclassing.
*/
public func prepareView() {
contentScaleFactor = MaterialDevice.scale
backgroundColor = MaterialColor.clear
contentInset = UIEdgeInsetsZero
}
......
......@@ -50,13 +50,17 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
public private(set) lazy var pulseLayers: Array<CAShapeLayer> = Array<CAShapeLayer>()
/// The opcaity value for the pulse animation.
@IBInspectable public var pulseOpacity: CGFloat = 0.12
@IBInspectable public var pulseOpacity: CGFloat = 0.25
/// The color of the pulse effect.
@IBInspectable public var pulseColor: UIColor?
@IBInspectable public var pulseColor: UIColor = MaterialColor.grey.base
/// The type of PulseAnimation.
public var pulseAnimation: PulseAnimation = .AtPointWithBacking
public var pulseAnimation: PulseAnimation = .AtPointWithBacking {
didSet {
visualLayer.masksToBounds = .CenterRadialBeyondBounds != pulseAnimation
}
}
/**
A property that manages an image for the visualLayer's contents
......@@ -516,7 +520,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
}
MaterialAnimation.delay(0.35) { [weak self] in
if let s: MaterialCollectionViewCell = self {
MaterialAnimation.pulseContractAnimation(s.layer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
MaterialAnimation.pulseContractAnimation(s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
}
}
}
......@@ -540,7 +544,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
*/
public override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.pulseContractAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -551,7 +555,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
*/
public override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
super.touchesCancelled(touches, withEvent: event)
MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.pulseContractAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -562,7 +566,6 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
when subclassing.
*/
public func prepareView() {
pulseColor = MaterialColor.black
contentScaleFactor = MaterialDevice.scale
prepareVisualLayer()
}
......
......@@ -147,6 +147,7 @@ public class MaterialLabel : UILabel {
:name: prepareView
*/
public func prepareView() {
contentScaleFactor = MaterialDevice.scale
textAlignment = .Left
}
}
\ No newline at end of file
......@@ -34,6 +34,7 @@ public enum PulseAnimation {
case None
case Center
case CenterWithBacking
case CenterRadialBeyondBounds
case Backing
case AtPoint
case AtPointWithBacking
......@@ -51,45 +52,41 @@ internal extension MaterialAnimation {
- Parameter duration: Animation duration.
- Parameter pulseLayers: An Array of CAShapeLayers used in the animation.
*/
internal static func pulseExpandAnimation(layer: CALayer, visualLayer: CALayer, pulseColor: UIColor?, pulseOpacity: CGFloat, point: CGPoint, width: CGFloat, height: CGFloat, inout pulseLayers: Array<CAShapeLayer>, pulseAnimation: PulseAnimation) {
internal static func pulseExpandAnimation(layer: CALayer, visualLayer: CALayer, pulseColor: UIColor, pulseOpacity: CGFloat, point: CGPoint, width: CGFloat, height: CGFloat, inout pulseLayers: Array<CAShapeLayer>, pulseAnimation: PulseAnimation) {
if .None != pulseAnimation {
if let color: UIColor = pulseColor {
if let n: CGFloat = width < height ? height : width {
if let pOpacity: CGFloat = pulseOpacity {
let bLayer: CAShapeLayer = CAShapeLayer()
let pLayer: CAShapeLayer = CAShapeLayer()
bLayer.addSublayer(pLayer)
pulseLayers.insert(bLayer, atIndex: 0)
visualLayer.addSublayer(bLayer)
MaterialAnimation.animationDisabled({
bLayer.frame = visualLayer.bounds
pLayer.bounds = CGRectMake(0, 0, n, n)
switch pulseAnimation {
case .Center, .CenterWithBacking:
pLayer.position = CGPointMake(width / 2, height / 2)
default:
pLayer.position = point
}
pLayer.cornerRadius = n / 2
pLayer.backgroundColor = color.colorWithAlphaComponent(pOpacity).CGColor
pLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMakeScale(0, 0))
})
bLayer.setValue(false, forKey: "animated")
switch pulseAnimation {
case .CenterWithBacking, .Backing, .AtPointWithBacking:
bLayer.addAnimation(MaterialAnimation.backgroundColor(color.colorWithAlphaComponent(pOpacity / 2), duration: 0.35), forKey: nil)
default:break
}
switch pulseAnimation {
case .Center, .CenterWithBacking, .AtPoint, .AtPointWithBacking:
pLayer.addAnimation(MaterialAnimation.scale(1, duration: 0.35), forKey: nil)
default:break
}
MaterialAnimation.delay(0.35, completion: {
bLayer.setValue(true, forKey: "animated")
})
if let n: CGFloat = .Center == pulseAnimation ? width < height ? width : height : width < height ? height : width {
let bLayer: CAShapeLayer = CAShapeLayer()
let pLayer: CAShapeLayer = CAShapeLayer()
bLayer.addSublayer(pLayer)
pulseLayers.insert(bLayer, atIndex: 0)
visualLayer.addSublayer(bLayer)
MaterialAnimation.animationDisabled({
bLayer.frame = visualLayer.bounds
pLayer.bounds = CGRectMake(0, 0, n, n)
switch pulseAnimation {
case .Center, .CenterWithBacking, .CenterRadialBeyondBounds:
pLayer.position = CGPointMake(width / 2, height / 2)
default:
pLayer.position = point
}
pLayer.cornerRadius = n / 2
pLayer.backgroundColor = pulseColor.colorWithAlphaComponent(pulseOpacity).CGColor
pLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMakeScale(0, 0))
})
bLayer.setValue(false, forKey: "animated")
switch pulseAnimation {
case .CenterWithBacking, .Backing, .AtPointWithBacking:
bLayer.addAnimation(MaterialAnimation.backgroundColor(pulseColor.colorWithAlphaComponent(pulseOpacity / 2), duration: 0.325), forKey: nil)
default:break
}
switch pulseAnimation {
case .Center, .CenterWithBacking, .CenterRadialBeyondBounds, .AtPoint, .AtPointWithBacking:
pLayer.addAnimation(MaterialAnimation.scale(1, duration: 0.325), forKey: nil)
default:break
}
MaterialAnimation.delay(0.325, completion: {
bLayer.setValue(true, forKey: "animated")
})
}
}
}
......@@ -100,29 +97,27 @@ internal extension MaterialAnimation {
- Parameter pulseColor: The UIColor for the pulse.
- Parameter pulseLayers: An Array of CAShapeLayers used in the animation.
*/
internal static func pulseContractAnimation(layer: CALayer, pulseColor: UIColor?, inout pulseLayers: Array<CAShapeLayer>, pulseAnimation: PulseAnimation) {
if let color: UIColor = pulseColor {
if let bLayer: CAShapeLayer = pulseLayers.popLast() {
let animated: Bool? = bLayer.valueForKey("animated") as? Bool
MaterialAnimation.delay(true == animated ? 0 : 0.15) {
if let pLayer: CAShapeLayer = bLayer.sublayers?.first as? CAShapeLayer {
switch pulseAnimation {
case .CenterWithBacking, .Backing, .AtPointWithBacking:
bLayer.addAnimation(MaterialAnimation.backgroundColor(color.colorWithAlphaComponent(0), duration: 0.35), forKey: nil)
default:break
}
switch pulseAnimation {
case .Center, .CenterWithBacking, .AtPoint, .AtPointWithBacking:
pLayer.addAnimation(MaterialAnimation.animationGroup([
MaterialAnimation.scale(1.35),
MaterialAnimation.backgroundColor(color.colorWithAlphaComponent(0))
], duration: 0.35), forKey: nil)
default:break
}
MaterialAnimation.delay(0.35) {
pLayer.removeFromSuperlayer()
bLayer.removeFromSuperlayer()
}
internal static func pulseContractAnimation(layer: CALayer, visualLayer: CALayer, pulseColor: UIColor, inout pulseLayers: Array<CAShapeLayer>, pulseAnimation: PulseAnimation) {
if let bLayer: CAShapeLayer = pulseLayers.popLast() {
let animated: Bool? = bLayer.valueForKey("animated") as? Bool
MaterialAnimation.delay(true == animated ? 0 : 0.15) {
if let pLayer: CAShapeLayer = bLayer.sublayers?.first as? CAShapeLayer {
switch pulseAnimation {
case .CenterWithBacking, .Backing, .AtPointWithBacking:
bLayer.addAnimation(MaterialAnimation.backgroundColor(pulseColor.colorWithAlphaComponent(0), duration: 0.325), forKey: nil)
default:break
}
switch pulseAnimation {
case .Center, .CenterWithBacking, .CenterRadialBeyondBounds, .AtPoint, .AtPointWithBacking:
pLayer.addAnimation(MaterialAnimation.animationGroup([
MaterialAnimation.scale(.Center == pulseAnimation ? 1 : 1.325),
MaterialAnimation.backgroundColor(pulseColor.colorWithAlphaComponent(0))
], duration: 0.325), forKey: nil)
default:break
}
MaterialAnimation.delay(0.325) {
pLayer.removeFromSuperlayer()
bLayer.removeFromSuperlayer()
}
}
}
......
......@@ -38,13 +38,17 @@ public class MaterialPulseView : MaterialView {
public private(set) lazy var pulseLayers: Array<CAShapeLayer> = Array<CAShapeLayer>()
/// The opcaity value for the pulse animation.
@IBInspectable public var pulseOpacity: CGFloat = 0.12
@IBInspectable public var pulseOpacity: CGFloat = 0.25
/// The color of the pulse effect.
@IBInspectable public var pulseColor: UIColor?
@IBInspectable public var pulseColor: UIColor = MaterialColor.grey.base
/// The type of PulseAnimation.
public var pulseAnimation: PulseAnimation = .AtPointWithBacking
public var pulseAnimation: PulseAnimation = .AtPointWithBacking {
didSet {
visualLayer.masksToBounds = .CenterRadialBeyondBounds != pulseAnimation
}
}
/**
Triggers the pulse animation.
......@@ -58,7 +62,7 @@ public class MaterialPulseView : MaterialView {
}
MaterialAnimation.delay(0.35) { [weak self] in
if let s: MaterialPulseView = self {
MaterialAnimation.pulseContractAnimation(s.layer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
MaterialAnimation.pulseContractAnimation(s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
}
}
}
......@@ -82,7 +86,7 @@ public class MaterialPulseView : MaterialView {
*/
public override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.pulseContractAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -93,19 +97,6 @@ public class MaterialPulseView : MaterialView {
*/
public override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
super.touchesCancelled(touches, withEvent: event)
MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
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 override func prepareView() {
super.prepareView()
pulseColor = MaterialColor.black
contentScaleFactor = MaterialDevice.scale
MaterialAnimation.pulseContractAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
}
......@@ -434,7 +434,7 @@ public class MaterialSwitch : UIControl {
/// Prepares the button.
private func prepareButton() {
button.pulseColor = nil
button.pulseAnimation = .None
button.addTarget(self, action: #selector(handleTouchUpInside), forControlEvents: .TouchUpInside)
button.addTarget(self, action: #selector(handleTouchDragInside), forControlEvents: .TouchDragInside)
button.addTarget(self, action: #selector(handleTouchUpOutsideOrCanceled), forControlEvents: .TouchCancel)
......
......@@ -49,13 +49,17 @@ public class MaterialTableViewCell : UITableViewCell {
public private(set) lazy var pulseLayers: Array<CAShapeLayer> = Array<CAShapeLayer>()
/// The opcaity value for the pulse animation.
@IBInspectable public var pulseOpacity: CGFloat = 0.12
@IBInspectable public var pulseOpacity: CGFloat = 0.25
/// The color of the pulse effect.
@IBInspectable public var pulseColor: UIColor?
@IBInspectable public var pulseColor: UIColor = MaterialColor.grey.base
/// The type of PulseAnimation.
public var pulseAnimation: PulseAnimation = .AtPointWithBacking
public var pulseAnimation: PulseAnimation = .AtPointWithBacking {
didSet {
visualLayer.masksToBounds = .CenterRadialBeyondBounds != pulseAnimation
}
}
/**
This property is the same as clipsToBounds. It crops any of the view's
......@@ -366,7 +370,7 @@ public class MaterialTableViewCell : UITableViewCell {
}
MaterialAnimation.delay(0.35) { [weak self] in
if let s: MaterialTableViewCell = self {
MaterialAnimation.pulseContractAnimation(s.layer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
MaterialAnimation.pulseContractAnimation(s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
}
}
}
......@@ -390,7 +394,7 @@ public class MaterialTableViewCell : UITableViewCell {
*/
public override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.pulseContractAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -401,7 +405,7 @@ public class MaterialTableViewCell : UITableViewCell {
*/
public override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
super.touchesCancelled(touches, withEvent: event)
MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.pulseContractAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -412,13 +416,12 @@ public class MaterialTableViewCell : UITableViewCell {
when subclassing.
*/
public func prepareView() {
prepareVisualLayer()
selectionStyle = .None
pulseColor = MaterialColor.black
contentScaleFactor = MaterialDevice.scale
imageView?.userInteractionEnabled = false
textLabel?.userInteractionEnabled = false
detailTextLabel?.userInteractionEnabled = false
prepareVisualLayer()
}
/// Prepares the visualLayer property.
......
......@@ -457,8 +457,9 @@ public class MaterialView : UIView {
when subclassing.
*/
public func prepareView() {
prepareVisualLayer()
contentScaleFactor = MaterialDevice.scale
backgroundColor = MaterialColor.white
prepareVisualLayer()
}
/// Prepares the visualLayer property.
......
......@@ -43,7 +43,7 @@ public class MenuView : MaterialPulseView {
*/
public override func prepareView() {
super.prepareView()
pulseColor = nil
pulseAnimation = .None
clipsToBounds = false
backgroundColor = nil
}
......
......@@ -172,9 +172,16 @@ public class MenuViewController : UIViewController {
}
}
/// A method that generally prepares the MenuViewController.
private func 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() {
view.clipsToBounds = true
view.contentScaleFactor = MaterialDevice.scale
prepareMenuView()
prepareRootViewController()
}
......
......@@ -51,7 +51,7 @@ public class NavigationBar : UINavigationBar {
private var rightSpacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
/// Reference to the backButton.
public private(set) lazy var backButton: FlatButton = FlatButton()
public private(set) lazy var backButton: IconButton = IconButton()
/**
The back button image writes to the backIndicatorImage property and
......@@ -402,6 +402,7 @@ public class NavigationBar : UINavigationBar {
backgroundColor = MaterialColor.white
depth = .Depth1
contentInsetPreset = .Square1
contentScaleFactor = MaterialDevice.scale
prepareBackButton()
}
......
......@@ -130,8 +130,15 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
popViewControllerAnimated(true)
}
/// Prepares the view.
private func 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() {
view.clipsToBounds = true
view.contentScaleFactor = MaterialDevice.scale
}
}
......@@ -35,7 +35,7 @@ public class SearchBar : StatusBarView {
public private(set) var textField: UITextField!
/// Reference to the clearButton.
public private(set) var clearButton: FlatButton!
public private(set) var clearButton: IconButton!
/// Handle the clearButton manually.
@IBInspectable public var clearButtonAutoHandleEnabled: Bool = true {
......@@ -126,10 +126,8 @@ public class SearchBar : StatusBarView {
/// Prepares the clearButton.
private func prepareClearButton() {
let image: UIImage? = MaterialIcon.cm.close
clearButton = FlatButton()
clearButton = IconButton()
clearButton.contentEdgeInsets = UIEdgeInsetsZero
clearButton.pulseColor = MaterialColor.black
clearButton.pulseOpacity = 0.12
clearButton.tintColor = placeholderTextColor
clearButton.setImage(image, forState: .Normal)
clearButton.setImage(image, forState: .Highlighted)
......
......@@ -748,9 +748,16 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
}
}
/// A method that generally prepares the SideNavigationController.
private func 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() {
view.clipsToBounds = true
view.contentScaleFactor = MaterialDevice.scale
prepareRootViewController()
prepareLeftView()
prepareRightView()
......
......@@ -136,6 +136,7 @@ public class StatusBarViewController : UIViewController {
*/
public func prepareView() {
view.clipsToBounds = true
view.contentScaleFactor = MaterialDevice.scale
prepareRootViewController()
}
......
......@@ -107,6 +107,7 @@ public class TabBar : MaterialView {
public override func prepareView() {
super.prepareView()
autoresizingMask = .FlexibleWidth
contentScaleFactor = MaterialDevice.scale
prepareBottomLayer()
}
......
......@@ -148,7 +148,7 @@ public class TextField : UITextField {
/// The placeholderLabel font value.
@IBInspectable public override var font: UIFont? {
didSet {
placeholderLabel.font = self.font
placeholderLabel.font = font
}
}
......@@ -243,87 +243,87 @@ public class TextField : UITextField {
}
}
/// Enables the clearFlatButton.
@IBInspectable public var enableClearFlatButton: Bool {
/// Enables the clearIconButton.
@IBInspectable public var enableClearIconButton: Bool {
get {
return nil != clearFlatButton
return nil != clearIconButton
}
set(value) {
if value {
if nil == clearFlatButton {
if nil == clearIconButton {
let image: UIImage? = MaterialIcon.cm.clear
clearFlatButton = FlatButton(frame: CGRectZero)
clearFlatButton!.contentEdgeInsets = UIEdgeInsetsZero
clearFlatButton!.pulseColor = nil
clearFlatButton!.tintColor = placeholderColor
clearFlatButton!.setImage(image, forState: .Normal)
clearFlatButton!.setImage(image, forState: .Highlighted)
clearIconButton = IconButton(frame: CGRectZero)
clearIconButton!.contentEdgeInsets = UIEdgeInsetsZero
clearIconButton!.pulseAnimation = .Center
clearIconButton!.tintColor = placeholderColor
clearIconButton!.setImage(image, forState: .Normal)
clearIconButton!.setImage(image, forState: .Highlighted)
clearButtonMode = .Never
rightViewMode = .WhileEditing
rightView = clearFlatButton
clearFlatButtonAutoHandle = clearFlatButtonAutoHandle ? true : false
rightView = clearIconButton
clearIconButtonAutoHandle = clearIconButtonAutoHandle ? true : false
}
} else {
clearFlatButton?.removeTarget(self, action: #selector(handleClearButton), forControlEvents: .TouchUpInside)
clearFlatButton = nil
clearIconButton?.removeTarget(self, action: #selector(handleClearButton), forControlEvents: .TouchUpInside)
clearIconButton = nil
}
}
}
/// Enables the automatic handling of the clearFlatButton.
@IBInspectable public var clearFlatButtonAutoHandle: Bool = true {
/// Enables the automatic handling of the clearIconButton.
@IBInspectable public var clearIconButtonAutoHandle: Bool = true {
didSet {
clearFlatButton?.removeTarget(self, action: #selector(handleClearButton), forControlEvents: .TouchUpInside)
if clearFlatButtonAutoHandle {
clearFlatButton?.addTarget(self, action: #selector(handleClearButton), forControlEvents: .TouchUpInside)
clearIconButton?.removeTarget(self, action: #selector(handleClearButton), forControlEvents: .TouchUpInside)
if clearIconButtonAutoHandle {
clearIconButton?.addTarget(self, action: #selector(handleClearButton), forControlEvents: .TouchUpInside)
}
}
}
/// Enables the visibilityFlatButton.
@IBInspectable public var enableVisibilityFlatButton: Bool {
/// Enables the visibilityIconButton.
@IBInspectable public var enableVisibilityIconButton: Bool {
get {
return nil != visibilityFlatButton
return nil != visibilityIconButton
}
set(value) {
if value {
if nil == visibilityFlatButton {
if nil == visibilityIconButton {
let image: UIImage? = MaterialIcon.visibility
visibilityFlatButton = FlatButton(frame: CGRectZero)
visibilityFlatButton!.contentEdgeInsets = UIEdgeInsetsZero
visibilityFlatButton!.pulseColor = nil
visibilityFlatButton!.tintColor = placeholderColor
visibilityFlatButton!.setImage(image, forState: .Normal)
visibilityFlatButton!.setImage(image, forState: .Highlighted)
visibilityFlatButton!.tintColor = placeholderColor.colorWithAlphaComponent(secureTextEntry ? 0.38 : 0.54)
visibilityIconButton = IconButton(frame: CGRectZero)
visibilityIconButton!.contentEdgeInsets = UIEdgeInsetsZero
visibilityIconButton!.pulseAnimation = .Center
visibilityIconButton!.tintColor = placeholderColor
visibilityIconButton!.setImage(image, forState: .Normal)
visibilityIconButton!.setImage(image, forState: .Highlighted)
visibilityIconButton!.tintColor = placeholderColor.colorWithAlphaComponent(secureTextEntry ? 0.38 : 0.54)
secureTextEntry = true
clearButtonMode = .Never
rightViewMode = .WhileEditing
rightView = visibilityFlatButton
visibilityFlatButtonAutoHandle = visibilityFlatButtonAutoHandle ? true : false
rightView = visibilityIconButton
visibilityIconButtonAutoHandle = visibilityIconButtonAutoHandle ? true : false
}
} else {
visibilityFlatButton?.removeTarget(self, action: #selector(handleClearButton), forControlEvents: .TouchUpInside)
visibilityFlatButton = nil
visibilityIconButton?.removeTarget(self, action: #selector(handleClearButton), forControlEvents: .TouchUpInside)
visibilityIconButton = nil
}
}
}
/// Enables the automatic handling of the visibilityFlatButton.
@IBInspectable public var visibilityFlatButtonAutoHandle: Bool = true {
/// Enables the automatic handling of the visibilityIconButton.
@IBInspectable public var visibilityIconButtonAutoHandle: Bool = true {
didSet {
visibilityFlatButton?.removeTarget(self, action: #selector(handleVisibilityButton), forControlEvents: .TouchUpInside)
if visibilityFlatButtonAutoHandle {
visibilityFlatButton?.addTarget(self, action: #selector(handleVisibilityButton), forControlEvents: .TouchUpInside)
visibilityIconButton?.removeTarget(self, action: #selector(handleVisibilityButton), forControlEvents: .TouchUpInside)
if visibilityIconButtonAutoHandle {
visibilityIconButton?.addTarget(self, action: #selector(handleVisibilityButton), forControlEvents: .TouchUpInside)
}
}
}
/// A reference to the clearFlatButton.
public private(set) var clearFlatButton: FlatButton?
/// A reference to the clearIconButton.
public private(set) var clearIconButton: IconButton?
/// A reference to the visibilityFlatButton.
public private(set) var visibilityFlatButton: FlatButton?
/// A reference to the visibilityIconButton.
public private(set) var visibilityIconButton: IconButton?
/**
An initializer that initializes the object with a NSCoder object.
......@@ -433,7 +433,7 @@ public class TextField : UITextField {
placeholderEditingDidEndAnimation()
}
/// Handles the clearFlatButton TouchUpInside event.
/// Handles the clearIconButton TouchUpInside event.
public func handleClearButton() {
if false == delegate?.textFieldShouldClear?(self) {
return
......@@ -441,10 +441,10 @@ public class TextField : UITextField {
text = nil
}
/// Handles the visibilityFlatButton TouchUpInside event.
/// Handles the visibilityIconButton TouchUpInside event.
public func handleVisibilityButton() {
secureTextEntry = !secureTextEntry
visibilityFlatButton?.tintColor = visibilityFlatButton?.tintColor.colorWithAlphaComponent(secureTextEntry ? 0.38 : 0.54)
visibilityIconButton?.tintColor = visibilityIconButton?.tintColor.colorWithAlphaComponent(secureTextEntry ? 0.38 : 0.54)
}
/**
......@@ -455,12 +455,13 @@ public class TextField : UITextField {
when subclassing.
*/
public func prepareView() {
super.placeholder = nil
masksToBounds = false
borderStyle = .None
backgroundColor = nil
super.placeholder = nil
textColor = MaterialColor.darkText.primary
font = RobotoFont.regularWithSize(16)
contentScaleFactor = MaterialDevice.scale
prepareDivider()
preparePlaceholderLabel()
prepareDetailLabel()
......@@ -472,8 +473,8 @@ public class TextField : UITextField {
if !animating {
layoutPlaceholderLabel()
layoutDetailLabel()
layoutClearFlatButton()
layoutVisibilityFlatButton()
layoutClearIconButton()
layoutVisibilityIconButton()
}
}
......@@ -518,18 +519,18 @@ public class TextField : UITextField {
detailLabel.frame = CGRectMake(0, divider.frame.origin.y + 8, width, h)
}
/// Layout the clearFlatButton.
public func layoutClearFlatButton() {
if let v: FlatButton = clearFlatButton {
/// Layout the clearIconButton.
public func layoutClearIconButton() {
if let v: IconButton = clearIconButton {
if 0 < width && 0 < height {
v.frame = CGRectMake(width - height, 0, height, height)
}
}
}
/// Layout the visibilityFlatButton.
public func layoutVisibilityFlatButton() {
if let v: FlatButton = visibilityFlatButton {
/// Layout the visibilityIconButton.
public func layoutVisibilityIconButton() {
if let v: IconButton = visibilityIconButton {
if 0 < width && 0 < height {
v.frame = CGRectMake(width - height, 0, height, height)
}
......
......@@ -467,6 +467,7 @@ public class TextView: UITextView {
when subclassing.
*/
public func prepareView() {
contentScaleFactor = MaterialDevice.scale
textContainerInset = MaterialEdgeInsetToValue(.None)
backgroundColor = MaterialColor.white
masksToBounds = false
......
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