-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
2,167 additions
and
467 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// AppDelegate.swift | ||
// JsonDemo | ||
// | ||
// Created by Gesen on 16/3/1. | ||
// Copyright © 2016年 Gesen. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import SwiftTheme | ||
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
var window: UIWindow? | ||
|
||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
|
||
// default: Red.json | ||
|
||
ThemeManager.setTheme(jsonName: "Red", path: .mainBundle) | ||
|
||
// status bar | ||
|
||
UIApplication.shared.theme_setStatusBarStyle("UIStatusBarStyle", animated: true) | ||
|
||
// navigation bar | ||
|
||
let navigationBar = UINavigationBar.appearance() | ||
|
||
navigationBar.theme_tintColor = "Global.barTextColor" | ||
navigationBar.theme_barTintColor = "Global.barTintColor" | ||
navigationBar.theme_titleTextAttributes = ThemeStringAttributesPicker(keyPath: "Global.barTextColor") { value -> [NSAttributedString.Key : AnyObject]? in | ||
guard let rgba = value as? String else { | ||
return nil | ||
} | ||
|
||
let color = UIColor(rgba: rgba) | ||
let shadow = NSShadow(); shadow.shadowOffset = CGSize.zero | ||
let titleTextAttributes = [ | ||
NSAttributedString.Key.foregroundColor: color, | ||
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16), | ||
NSAttributedString.Key.shadow: shadow | ||
] | ||
|
||
return titleTextAttributes | ||
} | ||
|
||
// tab bar | ||
|
||
let tabBar = UITabBar.appearance() | ||
|
||
tabBar.theme_tintColor = "Global.barTextColor" | ||
tabBar.theme_barTintColor = "Global.barTintColor" | ||
|
||
return true | ||
} | ||
|
||
func applicationWillResignActive(_ application: UIApplication) { } | ||
|
||
func applicationDidEnterBackground(_ application: UIApplication) { } | ||
|
||
func applicationWillEnterForeground(_ application: UIApplication) { } | ||
|
||
func applicationDidBecomeActive(_ application: UIApplication) { } | ||
|
||
func applicationWillTerminate(_ application: UIApplication) { } | ||
|
||
|
||
} | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github "marmelroy/Zip" | ||
github "jdg/MBProgressHUD" ~> 0.9.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// SelectThemeViewController.swift | ||
// JsonDemo | ||
// | ||
// Created by Gesen on 16/3/1. | ||
// Copyright © 2016年 Gesen. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class SelectThemeViewController: UIViewController, UIAlertViewDelegate { | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
view.theme_backgroundColor = "Global.backgroundColor" | ||
} | ||
|
||
@IBAction func tapRed(_ sender: AnyObject) { | ||
MyThemes.switchTo(.red) | ||
} | ||
|
||
@IBAction func tapYellow(_ sender: AnyObject) { | ||
MyThemes.switchTo(.yello) | ||
} | ||
|
||
@IBAction func tapBlue(_ sender: AnyObject) { | ||
guard MyThemes.isBlueThemeExist() else { | ||
|
||
let title = "Not Downloaded" | ||
let message = "Download the theme right now?" | ||
|
||
if #available(iOS 8.0, *) { | ||
|
||
let alert = UIAlertController(title: title, | ||
message: message, | ||
preferredStyle: .alert) | ||
|
||
alert.addAction(UIAlertAction( | ||
title: "Cancel", | ||
style: .cancel, | ||
handler: nil) | ||
) | ||
alert.addAction(UIAlertAction( | ||
title: "Sure", | ||
style: .default, | ||
handler: { [unowned self] _ in | ||
self.downloadStart() | ||
}) | ||
) | ||
|
||
present(alert, animated: true, completion: nil) | ||
|
||
} else { | ||
|
||
UIAlertView(title: title, | ||
message: message, | ||
delegate: self, | ||
cancelButtonTitle: "Cancel", | ||
otherButtonTitles: "Sure").show() | ||
|
||
} | ||
return | ||
} | ||
|
||
MyThemes.switchTo(.blue) | ||
} | ||
|
||
func alertView(_ alertView: UIAlertView, clickedButtonAt buttonIndex: Int) { | ||
if buttonIndex == 1 { | ||
downloadStart() | ||
} | ||
} | ||
|
||
fileprivate func downloadStart() { | ||
let HUD = navigationController!.showHUD("Download Theme...") | ||
|
||
MyThemes.downloadBlueTask() { isSuccess in | ||
HUD.label.text = isSuccess ? "Successful!" : "Failure!" | ||
HUD.mode = .text | ||
HUD.hide(animated: true, afterDelay: 1) | ||
|
||
if isSuccess { | ||
MyThemes.switchTo(.blue) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"SwitchNightCell":{"iconImage":"icon_night_dark"},"ListViewController":{"separatorColor":"#C6C5C5"},"ChangeThemeCell":{"buttonTitleColorHighlighted":"#AAA","buttonTitleColorNormal":"#000","buttonBackgroundColor":"#F4C600"},"SelectThemeCell":{"iconImage":"icon_theme_yellow"},"UIStatusBarStyle":"DarkContent","Global":{"textColor":"#000","backgroundColor":"#FFF","barTintColor":"#F4C600","barTextColor":"#000"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"SwitchNightCell":{"iconImage":"icon_night_light"},"ListViewController":{"separatorColor":"#ECF0F1"},"ChangeThemeCell":{"buttonTitleColorHighlighted":"#AAA","buttonTitleColorNormal":"#000","buttonBackgroundColor":"#ECF0F1"},"SelectThemeCell":{"iconImage":"icon_theme_light"},"UIStatusBarStyle":"LightContent","Global":{"textColor":"#ECF0F1","backgroundColor":"#292b38","barTintColor":"#01040D","barTextColor":"#FFF"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"SwitchNightCell":{"iconImage":"icon_night_dark"},"ListViewController":{"separatorColor":"#C6C5C5"},"ChangeThemeCell":{"buttonTitleColorHighlighted":"#555","buttonTitleColorNormal":"#FFF","buttonBackgroundColor":"#EB4F38"},"SelectThemeCell":{"iconImage":"icon_theme_red"},"UIStatusBarStyle":"LightContent","Global":{"textColor":"#000","backgroundColor":"#FFF","barTintColor":"#EB4F38","barTextColor":"#FFF"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"SwitchNightCell":{"iconImage":"icon_night_dark"},"ListViewController":{"separatorColor":"#C6C5C5"},"ChangeThemeCell":{"buttonTitleColorHighlighted":"#AAA","buttonTitleColorNormal":"#000","buttonBackgroundColor":"#F4C600"},"SelectThemeCell":{"iconImage":"icon_theme_yellow"},"UIStatusBarStyle":"DarkContent","Global":{"textColor":"#000","backgroundColor":"#FFF","barTintColor":"#F4C600","barTextColor":"#000"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// AboutCell.swift | ||
// JsonDemo | ||
// | ||
// Created by Gesen on 16/3/2. | ||
// Copyright © 2016年 Gesen. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class AboutCell: BaseCell { | ||
|
||
@IBOutlet weak var content: UILabel! | ||
|
||
override func awakeFromNib() { | ||
super.awakeFromNib() | ||
|
||
content.theme_textColor = "Global.textColor" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// BaseCell.swift | ||
// JsonDemo | ||
// | ||
// Created by Gesen on 16/3/14. | ||
// Copyright © 2016年 Gesen. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class BaseCell: UITableViewCell { | ||
|
||
override func awakeFromNib() { | ||
super.awakeFromNib() | ||
|
||
theme_backgroundColor = "Global.backgroundColor" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// ChangeThemeCell.swift | ||
// JsonDemo | ||
// | ||
// Created by Gesen on 16/3/2. | ||
// Copyright © 2016年 Gesen. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class ChangeThemeCell: BaseCell { | ||
|
||
@IBOutlet weak var changeTheme: UIButton! | ||
|
||
override func awakeFromNib() { | ||
super.awakeFromNib() | ||
|
||
changeTheme.theme_setTitleColor("ChangeThemeCell.buttonTitleColorNormal", forState: .normal) | ||
changeTheme.theme_setTitleColor("ChangeThemeCell.buttonTitleColorNormal", forState: .highlighted) | ||
changeTheme.theme_backgroundColor = "ChangeThemeCell.buttonBackgroundColor" | ||
changeTheme.layer.cornerRadius = changeTheme.bounds.size.width / 2 | ||
} | ||
|
||
@IBAction func tapChange(_ sender: UIButton) { | ||
MyThemes.switchToNext() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// ListViewController.swift | ||
// JsonDemo | ||
// | ||
// Created by Gesen on 16/3/1. | ||
// Copyright © 2016年 Gesen. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class ListViewController: UITableViewController { | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
tableView.theme_backgroundColor = "Global.backgroundColor" | ||
tableView.theme_separatorColor = "ListViewController.separatorColor" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// SelectThemeCell.swift | ||
// JsonDemo | ||
// | ||
// Created by Gesen on 16/3/2. | ||
// Copyright © 2016年 Gesen. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class SelectThemeCell: BaseCell { | ||
|
||
@IBOutlet weak var title: UILabel! | ||
@IBOutlet weak var themeIcon: UIImageView! | ||
|
||
override func awakeFromNib() { | ||
super.awakeFromNib() | ||
|
||
title.theme_textColor = "Global.textColor" | ||
themeIcon.theme_image = "SelectThemeCell.iconImage" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// SwitchNightCell.swift | ||
// JsonDemo | ||
// | ||
// Created by Gesen on 16/3/2. | ||
// Copyright © 2016年 Gesen. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import SwiftTheme | ||
|
||
class SwitchNightCell: BaseCell { | ||
|
||
@IBOutlet weak var title: UILabel! | ||
@IBOutlet weak var nightIcon: UIImageView! | ||
@IBOutlet weak var nightSwitch: UISwitch! | ||
|
||
override func awakeFromNib() { | ||
super.awakeFromNib() | ||
|
||
title.theme_textColor = "Global.textColor" | ||
nightIcon.theme_image = "SwitchNightCell.iconImage" | ||
|
||
updateNightSwitch() | ||
|
||
NotificationCenter.default.addObserver(self, selector: #selector(updateNightSwitch), name: NSNotification.Name(rawValue: ThemeUpdateNotification), object: nil) | ||
} | ||
|
||
@IBAction func changeNight(_ sender: UISwitch) { | ||
MyThemes.switchNight(sender.isOn) | ||
} | ||
|
||
@objc fileprivate func updateNightSwitch() { | ||
nightSwitch.isOn = MyThemes.isNight() | ||
} | ||
|
||
} |
Oops, something went wrong.