Skip to content

Commit

Permalink
update the action when direction button is tapped
Browse files Browse the repository at this point in the history
  • Loading branch information
makomori committed Dec 8, 2016
1 parent a91a6b2 commit f55f6d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Demo/AppDelegate.swift
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
TMGradientNavigationBar().setInitialBarGradientColor(direction: .horizontal, typeName: "SoundCloud")
TMGradientNavigationBar().setInitialBarGradientColor(direction: .vertical, typeName: "SoundCloud")
return true
}

Expand Down
2 changes: 1 addition & 1 deletion Demo/Base.lproj/Main.storyboard
Expand Up @@ -59,7 +59,7 @@
</connections>
</tableView>
<navigationItem key="navigationItem" id="XrG-PN-ODv">
<barButtonItem key="rightBarButtonItem" title="Vertical" id="lc8-vG-Syk">
<barButtonItem key="rightBarButtonItem" title="horizontal" id="lc8-vG-Syk">
<color key="tintColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<connections>
<action selector="directionButtonTapped:" destination="OR8-fU-3UN" id="ycW-eL-co9"/>
Expand Down
25 changes: 19 additions & 6 deletions Demo/TableViewController.swift
Expand Up @@ -12,16 +12,17 @@ import Tamamushi
class TableViewController: UITableViewController {

@IBOutlet var directionSwitchButton: UIBarButtonItem!

let colorNames = [
"SoundCloud",
"Facebook Messenger",
"Instagram",
"Flickr",
"Vine",
"Green to dark"
"YouTube",
"Pinky",
"Sunrise"
]

var lastSelectedIndexPath = IndexPath(row: 0, section: 0)
var gradientDirection = Direction.vertical

override func viewDidLoad() {
Expand All @@ -37,11 +38,18 @@ class TableViewController: UITableViewController {
switch gradientDirection {
case .vertical:
gradientDirection = .horizontal
directionSwitchButton.title = "horizontal"
directionSwitchButton.title = "vertical"
case .horizontal:
gradientDirection = .vertical
directionSwitchButton.title = "vertical"
directionSwitchButton.title = "horizontal"
}
if let bar = self.navigationController?.navigationBar {
setGradientBarWithIndexPath(indexPath: lastSelectedIndexPath, onBar: bar)
}
}

func setGradientBarWithIndexPath(indexPath: IndexPath, onBar: UINavigationBar) {
TMGradientNavigationBar().setGradientColorOnNavigationBar(bar: onBar, direction: gradientDirection, typeName: colorNames[indexPath.row])
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
Expand All @@ -56,7 +64,12 @@ class TableViewController: UITableViewController {

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let bar = self.navigationController?.navigationBar {
TMGradientNavigationBar().setGradientColorOnNavigationBar(bar: bar, direction: gradientDirection, typeName: colorNames[indexPath.row])
setGradientBarWithIndexPath(indexPath: indexPath, onBar: bar)
lastSelectedIndexPath = indexPath
}
}

override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.1
}
}

0 comments on commit f55f6d1

Please sign in to comment.