Commit bcfdc0bd by Daniel Dahan

updated Menu examples

parent 25fdd7c7
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_flash_auto_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_auto_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_auto_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_flash_off_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_off_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_off_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_flash_on_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_on_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_flash_on_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
...@@ -37,19 +37,32 @@ import UIKit ...@@ -37,19 +37,32 @@ import UIKit
import Material import Material
class ViewController: UIViewController { class ViewController: UIViewController {
/// Menu component. /// FabMenu component.
private var menu: Menu! private var fabMenu: Menu!
/// FlatMenu component.
private var flatMenu: Menu!
/// FlashMenu component.
private var flashMenu: Menu!
/// Default spacing size /// Default spacing size
let spacing: CGFloat = 16 let spacing: CGFloat = 16
/// Base button diameter, otherwise default to buttonSize (48 x 48) /// Diameter for FabButtons.
let diameter: CGFloat = 56 let diameter: CGFloat = 56
/// Height for FlatButtons.
let height: CGFloat = 36
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareMenuExample() prepareFabMenuExample()
prepareFlatbMenuExample()
prepareFlashMenuExample()
} }
/// Handle orientation. /// Handle orientation.
...@@ -57,28 +70,53 @@ class ViewController: UIViewController { ...@@ -57,28 +70,53 @@ class ViewController: UIViewController {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
// Handle orientation change. // Handle orientation change.
menu.origin = CGPointMake(view.bounds.height - diameter - spacing, view.bounds.width - diameter - spacing) fabMenu.origin = CGPointMake(view.bounds.height - diameter - spacing, view.bounds.width - diameter - spacing)
flatMenu.origin = CGPointMake(spacing, view.bounds.height - height - spacing)
} }
/// Handle the base button touch event. /// Handle the fabMenu touch event.
internal func handleOpenMenu() { internal func handleFabMenu() {
// Only trigger open and close animations when enabled. // Only trigger open and close animations when enabled.
if menu.enabled { if fabMenu.enabled {
let image: UIImage? let image: UIImage?
if menu.opened { if fabMenu.opened {
menu.close() fabMenu.close()
image = UIImage(named: "ic_add_white") image = UIImage(named: "ic_add_white")
} else { } else {
menu.open() { (button: UIButton) in fabMenu.open() { (button: UIButton) in
(button as? MaterialButton)?.pulse() (button as? MaterialButton)?.pulse()
} }
image = UIImage(named: "ic_close_white") image = UIImage(named: "ic_close_white")
} }
// Add a nice rotation animation to the base button. // Add a nice rotation animation to the base button.
(menu.buttons?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(1)) (fabMenu.buttons?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(1))
menu.buttons?.first?.setImage(image, forState: .Normal) fabMenu.buttons?.first?.setImage(image, forState: .Normal)
menu.buttons?.first?.setImage(image, forState: .Highlighted) fabMenu.buttons?.first?.setImage(image, forState: .Highlighted)
}
}
/// Handle the flatMenu touch event.
internal func handleFlatMenu() {
// Only trigger open and close animations when enabled.
if flatMenu.enabled {
if flatMenu.opened {
flatMenu.close()
} else {
flatMenu.open()
}
}
}
/// Handle the flashMenu touch event.
internal func handleFlashMenu() {
// Only trigger open and close animations when enabled.
if flashMenu.enabled {
if flashMenu.opened {
flashMenu.close()
} else {
flashMenu.open()
}
} }
} }
...@@ -87,8 +125,8 @@ class ViewController: UIViewController { ...@@ -87,8 +125,8 @@ class ViewController: UIViewController {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
} }
/// Prepares the Menu example. /// Prepares the FabMenu example.
private func prepareMenuExample() { private func prepareFabMenuExample() {
var image: UIImage? = UIImage(named: "ic_add_white") var image: UIImage? = UIImage(named: "ic_add_white")
let btn1: FabButton = FabButton() let btn1: FabButton = FabButton()
/** /**
...@@ -98,7 +136,7 @@ class ViewController: UIViewController { ...@@ -98,7 +136,7 @@ class ViewController: UIViewController {
btn1.pulseColor = nil btn1.pulseColor = nil
btn1.setImage(image, forState: .Normal) btn1.setImage(image, forState: .Normal)
btn1.setImage(image, forState: .Highlighted) btn1.setImage(image, forState: .Highlighted)
btn1.addTarget(self, action: "handleOpenMenu", forControlEvents: .TouchUpInside) btn1.addTarget(self, action: "handleFabMenu", forControlEvents: .TouchUpInside)
view.addSubview(btn1) view.addSubview(btn1)
image = UIImage(named: "ic_create_white") image = UIImage(named: "ic_create_white")
...@@ -123,10 +161,86 @@ class ViewController: UIViewController { ...@@ -123,10 +161,86 @@ class ViewController: UIViewController {
view.addSubview(btn4) view.addSubview(btn4)
// Initialize the menu and setup the configuration options. // Initialize the menu and setup the configuration options.
menu = Menu(origin: CGPointMake(view.bounds.width - diameter - spacing, view.bounds.height - diameter - spacing)) fabMenu = Menu(origin: CGPointMake(view.bounds.width - diameter - spacing, view.bounds.height - diameter - spacing))
menu.direction = .Up fabMenu.direction = .Up
menu.baseSize = CGSizeMake(diameter, diameter) fabMenu.baseSize = CGSizeMake(diameter, diameter)
menu.buttons = [btn1, btn2, btn3, btn4] fabMenu.buttons = [btn1, btn2, btn3, btn4]
}
/// Prepares the FlatMenu example.
private func prepareFlatbMenuExample() {
let btn1: FlatButton = FlatButton()
btn1.addTarget(self, action: "handleFlatMenu", forControlEvents: .TouchUpInside)
btn1.setTitleColor(MaterialColor.white, forState: .Normal)
btn1.backgroundColor = MaterialColor.blue.accent3
btn1.pulseColor = MaterialColor.white
btn1.setTitle("Base", forState: .Normal)
view.addSubview(btn1)
let btn2: FlatButton = FlatButton()
btn2.setTitleColor(MaterialColor.blue.accent3, forState: .Normal)
btn2.borderColor = MaterialColor.blue.accent3
btn2.pulseColor = MaterialColor.blue.accent3
btn2.borderWidth = .Border1
btn2.setTitle("Item", forState: .Normal)
view.addSubview(btn2)
let btn3: FlatButton = FlatButton()
btn3.setTitleColor(MaterialColor.blue.accent3, forState: .Normal)
btn3.borderColor = MaterialColor.blue.accent3
btn3.pulseColor = MaterialColor.blue.accent3
btn3.borderWidth = .Border1
btn3.setTitle("Item", forState: .Normal)
view.addSubview(btn3)
let btn4: FlatButton = FlatButton()
btn4.setTitleColor(MaterialColor.blue.accent3, forState: .Normal)
btn4.borderColor = MaterialColor.blue.accent3
btn4.pulseColor = MaterialColor.blue.accent3
btn4.borderWidth = .Border1
btn4.setTitle("Item", forState: .Normal)
view.addSubview(btn4)
// Initialize the menu and setup the configuration options.
flatMenu = Menu(origin: CGPointMake(spacing, view.bounds.height - height - spacing))
flatMenu.direction = .Up
flatMenu.spacing = 8
flatMenu.buttonSize = CGSizeMake(120, height)
flatMenu.buttons = [btn1, btn2, btn3, btn4]
}
/// Prepares the FlashMenu example.
private func prepareFlashMenuExample() {
var image: UIImage? = UIImage(named: "ic_flash_auto_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn1: FlatButton = FlatButton()
btn1.pulseColor = MaterialColor.blueGrey.darken4
btn1.tintColor = MaterialColor.blueGrey.darken4
btn1.setImage(image, forState: .Normal)
btn1.setImage(image, forState: .Highlighted)
btn1.addTarget(self, action: "handleFlashMenu", forControlEvents: .TouchUpInside)
view.addSubview(btn1)
image = UIImage(named: "ic_flash_off_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn2: FlatButton = FlatButton()
btn2.pulseColor = MaterialColor.blueGrey.darken4
btn2.tintColor = MaterialColor.blueGrey.darken4
btn2.setImage(image, forState: .Normal)
btn2.setImage(image, forState: .Highlighted)
view.addSubview(btn2)
image = UIImage(named: "ic_flash_on_white")?.imageWithRenderingMode(.AlwaysTemplate)
let btn3: FlatButton = FlatButton()
btn3.pulseColor = MaterialColor.blueGrey.darken4
btn3.tintColor = MaterialColor.blueGrey.darken4
btn3.setImage(image, forState: .Normal)
btn3.setImage(image, forState: .Highlighted)
view.addSubview(btn3)
// Initialize the menu and setup the configuration options.
flashMenu = Menu(origin: CGPointMake(300, 100))
flashMenu.direction = .Left
flashMenu.buttonSize = btn1.intrinsicContentSize()
flashMenu.buttons = [btn1, btn2, btn3]
} }
} }
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Material' s.name = 'Material'
s.version = '1.31.0' s.version = '1.31.1'
s.license = 'BSD' s.license = 'BSD'
s.summary = 'A beautiful graphics framework for Material Design in Swift.' s.summary = 'A beautiful graphics framework for Material Design in Swift.'
s.homepage = 'http://cosmicmind.io' s.homepage = 'http://cosmicmind.io'
......
...@@ -166,7 +166,17 @@ A FabButton is essential to Material Design's overall look. Below showcases its ...@@ -166,7 +166,17 @@ A FabButton is essential to Material Design's overall look. Below showcases its
A Menu manages a group of UIButtons that may be animated open in the Up, Down, Left, and Right directions. The animations are fully customizable. A Menu manages a group of UIButtons that may be animated open in the Up, Down, Left, and Right directions. The animations are fully customizable.
![MaterialFabButton](http://www.cosmicmind.io/MK/MaterialMenu.gif) Below is an Example using FabButtons.
![MaterialFabButton](http://www.cosmicmind.io/MK/MaterialFabMenu.gif)
Below is an Example using FlatButtons.
![MaterialFabButton](http://www.cosmicmind.io/MK/MaterialFlatMenu.gif)
Below is an Example using FlatButtons with images.
![MaterialFabButton](http://www.cosmicmind.io/MK/MaterialFlashMenu.gif)
[Learn More About Menu](https://github.com/CosmicMind/Material/wiki/Menu) [Learn More About Menu](https://github.com/CosmicMind/Material/wiki/Menu)
......
...@@ -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.31.0</string> <string>1.31.1</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -448,7 +448,7 @@ public class Menu { ...@@ -448,7 +448,7 @@ public class Menu {
button.frame.size = buttonSize button.frame.size = buttonSize
button.frame.origin.x = origin.x + (size.width - buttonSize.width) / 2 button.frame.origin.x = origin.x + (size.width - buttonSize.width) / 2
button.frame.origin.y = origin.y + (size.height - buttonSize.height) / 2 button.frame.origin.y = origin.y + (size.height - buttonSize.height) / 2
button.layer.zPosition = CGFloat(10000 - i) button.layer.zPosition = CGFloat(10000 - v.count - i)
} }
} }
} }
...@@ -456,10 +456,12 @@ public class Menu { ...@@ -456,10 +456,12 @@ public class Menu {
/// Disable the Menu if buttons exist. /// Disable the Menu if buttons exist.
private func disable() { private func disable() {
if let _: Array<UIButton> = buttons { if let v: Array<UIButton> = buttons {
if 0 < v.count {
enabled = false enabled = false
} }
} }
}
/** /**
Enable the Menu if the last button is equal to the passed in button. Enable the Menu if the last button is equal to the passed in button.
......
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