Skip to content

Commit

Permalink
Add 2 functions (normalSelected, alwaysSelected)
Browse files Browse the repository at this point in the history
  • Loading branch information
seungyounyi committed Mar 8, 2017
1 parent f545117 commit 94b8c0e
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Updates
## [v2.0.11](https://github.com/younatics/YNDropDownMenu/releases/tag/2.0.11)
* Add `alwaysSelected(at index: Int)` method in `YNDropDownView`
* Add `normalSelected(at index: Int)` method in `YNDropDownView` and `YNDropDownMenu`

## [v2.0.10](https://github.com/younatics/YNDropDownMenu/releases/tag/2.0.10)
* Add `changeMenu(title: String, status: YNStatus, at index: Int)` method in `YNDropDownView` and `YNDropDownMenu`
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class DropDownView: YNDropDownView {

// Change View At Index
self.changeView(view: UIView(), at: 3)

// Always Selected Menu
self.alwaysSelected(at: 0)
self.normalSelected(at: 0)
}
```

Expand All @@ -94,6 +98,7 @@ view.enabledMenu(at: 3)
Always/Normal selected button label
```swift
view.alwaysSelected(at: 0)
view.normalSelected(at: 0)
```

Button Image with 3 situations (normal, selected, disabled)
Expand Down Expand Up @@ -159,7 +164,6 @@ Change Bottom Line
```swift
view.bottomLine.backgroundColor = UIColor.black
view.bottomLine.isHidden = false

```


Expand Down
2 changes: 1 addition & 1 deletion YNDropDownMenu.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'YNDropDownMenu'
s.version = '2.0.10'
s.version = '2.0.11'
s.summary = 'Awesome Dropdown menu for iOS with Swift 3'

s.description = <<-DESC
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>
6 changes: 5 additions & 1 deletion YNDropDownMenu/Example/DropDownViews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ class ZBFilterMemeView: YNDropDownView {
self.initViews()
}
@IBAction func confirmButtonClicked(_ sender: Any) {
self.normalSelected(at: 1)
self.hideMenu()
}
@IBAction func cancelButtonClicked(_ sender: Any) {
// self.changeMenu(title: "Changed", at: 1)
self.changeMenu(title: "Changed", status: .selected, at: 1)
// self.changeMenu(title: "Changed", status: .selected, at: 0)
self.alwaysSelected(at: 1)
// self.alwaysSelected(at: 2)
// self.alwaysSelected(at: 3)
self.hideMenu()

}
Expand Down
14 changes: 14 additions & 0 deletions YNDropDownMenu/Source/YNDropDownDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ public protocol YNDropDownDelegate: class {
*/
func changeView(view: UIView, at index: Int)

/**
Make button label always selected. (not button image)

- Parameter index: Index should be smaller than your menu counts
*/
func alwaysSelected(at index: Int)

/**
Make button label normal that selected before. (not button image)

- Parameter index: Index should be smaller than your menu counts
*/
func normalSelected(at index: Int)

}
36 changes: 33 additions & 3 deletions YNDropDownMenu/Source/YNDropDownMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ open class YNDropDownMenu: UIView, YNDropDownDelegate {
}
}

internal var alwaysOnIndex: Int?
internal var alwaysOnIndex: [Int]?
internal var dropDownViewTitles: [String]?

/// Blur effect view will changed if you change this popperty. Backgorund view don't have to be blur view (e.g. UIColor.black)
Expand Down Expand Up @@ -180,12 +180,39 @@ open class YNDropDownMenu: UIView, YNDropDownDelegate {
*/
open func alwaysSelected(at index: Int) {
self.checkIndex(index: index)
self.alwaysOnIndex = index

guard let alwaysOnIndex = self.alwaysOnIndex else { return }

if alwaysOnIndex.contains(index) {
print("YNDropDownMenu: Alreay index is contained in Array")
} else {
self.alwaysOnIndex?.append(index)
}

dropDownButtons?[index].buttonLabel.textColor = self.buttonlabelFontColors?.selected
dropDownButtons?[index].buttonLabel.font = self.buttonlabelFonts?.selected
}

/**
Make button label normal that selected before. (not button image)

- Parameter index: Index should be smaller than your menu counts
*/
open func normalSelected(at index: Int) {
self.checkIndex(index: index)

guard let alwaysOnIndex = self.alwaysOnIndex else { return }

if let value = alwaysOnIndex.index(of: index) {
self.alwaysOnIndex!.remove(at: value)
} else {
print("YNDropDownMenu: Index is not contained in Array")
}

dropDownButtons?[index].buttonLabel.textColor = self.buttonlabelFontColors?.normal
dropDownButtons?[index].buttonLabel.font = self.buttonlabelFonts?.normal
}

/**
Make button disabled (title and image you set)

Expand Down Expand Up @@ -377,7 +404,9 @@ open class YNDropDownMenu: UIView, YNDropDownDelegate {
_buttonImageView.layer.transform = CATransform3DMakeRotation(CGFloat(M_PI), 0.0, 0.0, 0.0);
_buttonImageView.image = self.buttonImages?.normal
}
if self.alwaysOnIndex != yNDropDownButton.tag {

guard let alwaysOnIndex = self.alwaysOnIndex else { return }
if !alwaysOnIndex.contains(yNDropDownButton.tag) {
yNDropDownButton.buttonLabel.textColor = self.buttonlabelFontColors?.normal
yNDropDownButton.buttonLabel.font = self.buttonlabelFonts?.normal
}
Expand All @@ -403,6 +432,7 @@ open class YNDropDownMenu: UIView, YNDropDownDelegate {

internal func initViews() {
self.clipsToBounds = true
self.alwaysOnIndex = [Int]()

self.backgroundColor = UIColor.white
self.dropDownButtons = [YNDropDownButton]()
Expand Down
19 changes: 19 additions & 0 deletions YNDropDownMenu/Source/YNDropDownView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,23 @@ open class YNDropDownView: UIView {
open func changeView(view: UIView, at index: Int) {
self.delegate?.changeView(view: view, at: index)
}

/**
Make button label always selected. (not button image)

- Parameter index: Index should be smaller than your menu counts
*/
open func alwaysSelected(at index: Int) {
self.delegate?.alwaysSelected(at: index)
}

/**
Make button label normal that selected before. (not button image)

- Parameter index: Index should be smaller than your menu counts
*/
open func normalSelected(at index: Int) {
self.delegate?.normalSelected(at: index)
}

}

0 comments on commit 94b8c0e

Please sign in to comment.