Skip to content

Commit

Permalink
may be useful at this time
Browse files Browse the repository at this point in the history
  • Loading branch information
seungyounyi committed Feb 21, 2017
1 parent 6de6f85 commit ceaf9ee
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 59 deletions.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 3 additions & 6 deletions Example/YNDropDownMenu/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ class ViewController: UIViewController {
super.viewDidLoad()

let ZBdropDownViews = Bundle.main.loadNibNamed("ZBDropDownMenu", owner: nil, options: nil) as? [UIView]
let FFA409 = UIColor(colorLiteralRed: 255/255, green: 164/255, blue: 9/255, alpha: 1.0)

if let _ZBdropDownViews = ZBdropDownViews {
let view = YNDropDownMenu(frame: CGRect(x: 0, y: 20, width: UIScreen.main.bounds.size.width, height: 38), dropDownViews: _ZBdropDownViews, dropDownViewTitles: ["Apple", "Banana", "Kiwi", "Pear"])
// view.menuLabelFontSize = 20
view.setImageWhen(normal: UIImage(named: "arrow_nor"), highlighted: UIImage(named: "arrow_sel"), selected: UIImage(named: "arrow_sel"), disabled: UIImage(named: "arrow_dim"))

view.setLabelColorWhen(normal: UIColor.black, highlighted: FFA409, selected: FFA409, disabled: UIColor.gray)
self.view.addSubview(view)
}



}
}

override func didReceiveMemoryWarning() {
Expand Down
6 changes: 3 additions & 3 deletions YNDropDownMenu.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

Pod::Spec.new do |s|
s.name = 'YNDropDownMenu'
s.version = '0.2.4'
s.summary = 'YNDropDownMenu is created to make drop down menu. You can simply add views and titles and it is done!'
s.version = '0.3.0'
s.summary = 'YNDropDownMenu is created to make drop down menu with Swift3'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
Expand All @@ -18,7 +18,7 @@ Pod::Spec.new do |s|
# * Finally, don't worry about the indent, CocoaPods strips it!

s.description = <<-DESC
TODO: This project is made by iOS Developer in Zigbang. You can simply add views and labels to project. It will make dropdown menu easily
TODO: You can init with frame. Button Images, Labels are all optional. See example in my github
DESC

s.homepage = 'https://github.com/younatics/YNDropDownMenu'
Expand Down
6 changes: 6 additions & 0 deletions YNDropDownMenu/Classes/YNDropDownButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class YNDropDownButton: UIButton {
}
}
open var labelFontColors: YNFontColor?

override init(frame: CGRect) {
super.init(frame: frame)
self.initView()

}

public init(frame: CGRect, buttonLabelText: String?) {
super.init(frame: frame)
Expand Down
103 changes: 53 additions & 50 deletions YNDropDownMenu/Classes/YNDropDownMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import UIKit
open class YNDropDownMenu: UIView {
private var opened: Bool = false
private var openedView = UIView()
private var openedArrowView = UIView()
private var openedArrowView = UIImageView()
private var openedYNDropDownButton = YNDropDownButton()

private var dropDownButtons: [YNDropDownButton]?
private var menuHeight: CGFloat = 0.0
Expand All @@ -30,6 +31,7 @@ open class YNDropDownMenu: UIView {
}
}
private var buttonImages: YNImages?
private var buttonlabelFontColors: YNFontColor?

public init(frame: CGRect, dropDownViews: [UIView], dropDownViewTitles: [String]) {
super.init(frame: frame)
Expand All @@ -53,73 +55,70 @@ open class YNDropDownMenu: UIView {

// Use this function when your menu button image is all same
open func setImageWhen(normal: UIImage?, highlighted: UIImage?, selected: UIImage?, disabled: UIImage?) {
let yNImages = YNImages.init(normal: normal, highlighted: highlighted, selected: selected, disabled: disabled)
buttonImages = YNImages.init(normal: normal, highlighted: highlighted, selected: selected, disabled: disabled)

for i in 0..<numberOfMenu {
dropDownButtons?[i].buttonImages = yNImages
dropDownButtons?[i].buttonImages = buttonImages
}
}

open func setImageWhen(normal: UIImage?, highlighted: UIImage?, selected: UIImage?, disabled: UIImage?, atIndex: Int) {
let yNImages = YNImages.init(normal: normal, highlighted: highlighted, selected: selected, disabled: disabled)
dropDownButtons?[atIndex].buttonImages = yNImages
}


open func setLabelColorWhen(normal: UIColor, highlighted: UIColor, selected: UIColor, disabled: UIColor) {
let yNFontColor = YNFontColor.init(normal: normal, highlighted: highlighted, selected: selected, disabled: disabled)
buttonlabelFontColors = YNFontColor.init(normal: normal, highlighted: highlighted, selected: selected, disabled: disabled)
for i in 0..<numberOfMenu {
dropDownButtons?[i].labelFontColors = yNFontColor
}
}

open func setLabelColorAtIndexWhen(normal: UIColor, highlighted: UIColor, selected: UIColor, disabled: UIColor, atIndex: Int) {
let yNFontColor = YNFontColor.init(normal: normal, highlighted: highlighted, selected: selected, disabled: disabled)
dropDownButtons?[atIndex].labelFontColors = yNFontColor
}

open func openMenuAt(index: Int) {
for subview in self.subviews {


dropDownButtons?[i].labelFontColors = buttonlabelFontColors
}
}


@objc private func menuClicked(_ sender: YNDropDownButton) {
open func showAndHideMenuAt(index: Int) {
var dropDownView = UIView()

var buttonImageView = UIImageView()
var yNDropDownButton = YNDropDownButton()

for subview in self.subviews {
if subview.tag == sender.tag + 100 {
if subview.tag == index + 100 {
dropDownView = subview
}
}
if let buttonImageView = sender.buttonImageView {
if openedView != dropDownView && opened {
hideMenu(arrowView: openedArrowView, dropDownMenu: openedView, didComplete: {
self.showMenu(arrowView: buttonImageView, dropDownMenu: dropDownView, didComplete: nil)
})
openedArrowView = buttonImageView
openedView = dropDownView
return
}

if subview.tag == index {
if subview.isKind(of: YNDropDownButton.self) {
let _subview = subview as! YNDropDownButton
yNDropDownButton = _subview
buttonImageView = _subview.buttonImageView
}
}
}

if openedView != dropDownView && opened {
hideMenu(yNDropDownButton: openedYNDropDownButton, arrowView: openedArrowView, dropDownMenu: openedView, didComplete: {
self.showMenu(yNDropDownButton: yNDropDownButton, arrowView: buttonImageView, dropDownMenu: dropDownView, didComplete: nil)
})
openedYNDropDownButton = yNDropDownButton
openedArrowView = buttonImageView
openedView = dropDownView

if !opened {
showMenu(arrowView: buttonImageView, dropDownMenu: dropDownView, didComplete: nil)
} else {
hideMenu(arrowView: buttonImageView, dropDownMenu: dropDownView, didComplete: nil)
}
opened = !opened
return
}

openedYNDropDownButton = yNDropDownButton
openedArrowView = buttonImageView
openedView = dropDownView

if !opened {
showMenu(yNDropDownButton: yNDropDownButton, arrowView: buttonImageView, dropDownMenu: dropDownView, didComplete: nil)
} else {
hideMenu(yNDropDownButton: yNDropDownButton, arrowView: buttonImageView, dropDownMenu: dropDownView, didComplete: nil)

}
opened = !opened

}

@objc private func menuClicked(_ sender: YNDropDownButton) {
self.showAndHideMenuAt(index: sender.tag)
}

private func showMenu(arrowView: UIView, dropDownMenu: UIView, didComplete: (()-> Void)?) {
private func showMenu(yNDropDownButton: YNDropDownButton, arrowView: UIImageView, dropDownMenu: UIView, didComplete: (()-> Void)?) {
dropDownMenu.isHidden = false

UIView.animate(
withDuration: self.showMenuDuration,
delay: 0,
Expand All @@ -129,14 +128,17 @@ open class YNDropDownMenu: UIView {
animations: {
dropDownMenu.frame.origin.y = CGFloat(self.menuHeight)
self.frame = CGRect(x: 0, y: self.frame.origin.y, width: self.frame.width, height: dropDownMenu.frame.height + CGFloat(self.menuHeight))
arrowView.layer.transform = CATransform3DMakeRotation(CGFloat(M_PI), 1.0, 0.0, 0.0);
arrowView.layer.transform = CATransform3DMakeRotation(CGFloat(M_PI), 1.0, 0.0, 0.0)
arrowView.image = self.buttonImages?.highlighted
yNDropDownButton.buttonLabel.textColor = self.buttonlabelFontColors?.selected

}, completion: { (completion) in
guard let block = didComplete else { return }
block()
})
}

private func hideMenu(arrowView: UIView, dropDownMenu: UIView, didComplete: (()-> Void)?) {
private func hideMenu(yNDropDownButton: YNDropDownButton,arrowView: UIImageView, dropDownMenu: UIView, didComplete: (()-> Void)?) {
dropDownMenu.isHidden = true

UIView.animate(
Expand All @@ -149,7 +151,9 @@ open class YNDropDownMenu: UIView {
dropDownMenu.frame.origin.y = CGFloat(self.menuHeight)
self.frame = CGRect(x: 0.0, y: self.frame.origin.y, width: self.frame.width, height: CGFloat(self.menuHeight))
arrowView.layer.transform = CATransform3DMakeRotation(CGFloat(M_PI), 0.0, 0.0, 0.0);

arrowView.image = self.buttonImages?.normal
yNDropDownButton.buttonLabel.textColor = self.buttonlabelFontColors?.normal

}, completion: { (completion) in
guard let block = didComplete else { return }
block()
Expand Down Expand Up @@ -188,5 +192,4 @@ open class YNDropDownMenu: UIView {

}
}

}

0 comments on commit ceaf9ee

Please sign in to comment.