Skip to content

Commit

Permalink
init project
Browse files Browse the repository at this point in the history
  • Loading branch information
ltransun-asterisk committed Jun 20, 2017
1 parent 41e25d8 commit 6339a74
Show file tree
Hide file tree
Showing 39 changed files with 1,859 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint
*.DS_Store

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.

Carthage/Checkouts
Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
578 changes: 578 additions & 0 deletions BaseMVC.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions BaseMVC.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions BaseMVC/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
</dict>
</plist>
39 changes: 39 additions & 0 deletions BaseMVC/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

// config realm
RealmManager.config()

// return
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

}
118 changes: 118 additions & 0 deletions BaseMVC/Sources/Controllers/BaseViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import UIKit

class BaseViewController: UIViewController, UIGestureRecognizerDelegate {

// MARK: - IBOutlet

// MARK: - Varialbes

// MARK: - View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()

self.navigationController?.interactivePopGestureRecognizer?.delegate = self
self.createBackMenuButton()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

if let count = self.navigationController?.viewControllers.count,
count > 1 {
self.enableSwipeBack(enable: true)
} else {
self.enableSwipeBack(enable: false)
}
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// MARK: - Navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}

// MARK: - Setup View
private func createBackMenuButton() {

if (self.navigationController?.viewControllers.count ?? 0) > 1 {
// add back
self.addBtnBackNav()
} else {
self.navigationItem.leftBarButtonItem = nil
self.navigationItem.hidesBackButton = true
}
}

func enableSwipeBack(enable: Bool) {
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = enable
}

func setNavTitle(title: String?) {
self.navigationItem.title = title
}

func addBtnBackNav(tinColor: UIColor? = nil) {
let backButton = self.createBtnNavWithImage(image: #imageLiteral(resourceName: "ic_arrow_back"), target: self, action: #selector(BaseViewController.actionTouchBtnBack), tinColor: tinColor)
self.navigationItem.setLeftBarButton(UIBarButtonItem(customView: backButton), animated: false)
}

func addBtnLeftNavWithImage(image: UIImage?, tinColor: UIColor? = nil) {
let leftButton = self.createBtnNavWithImage(image: image, target: self, action: #selector(BaseViewController.actionTouchBtnLeft), tinColor: tinColor)
self.navigationItem.setLeftBarButton(UIBarButtonItem(customView: leftButton), animated: false)
}

func addBtnRightNavWithImage(image: UIImage?, tinColor: UIColor? = nil) {
let rightButton = self.createBtnNavWithImage(image: image, target: self, action: #selector(BaseViewController.actionTouchBtnRight), tinColor: tinColor)
self.navigationItem.setRightBarButton(UIBarButtonItem(customView: rightButton), animated: false)
}

func addBtnLeftNavWithTitle(title: String?) {
if let title = title {
let leftNavBtn = UIBarButtonItem(title: title, style: .plain, target: self, action: #selector(BaseViewController.actionTouchBtnLeft))
self.navigationItem.leftBarButtonItem = leftNavBtn
}
}

func addBtnRightNavWithTitle(title: String?) {
let rightNavBtn = UIBarButtonItem(title: title, style: .plain, target: self, action: #selector(BaseViewController.actionTouchBtnRight))
self.navigationItem.rightBarButtonItem = rightNavBtn
}

private func createBtnNavWithImage(image: UIImage?, target: AnyObject?, action: Selector, tinColor: UIColor? = nil) -> UIButton {
let navButton: UIButton = UIButton(type: UIButtonType.system)
navButton.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
navButton.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
navButton.setImage(image, for: UIControlState.normal)
navButton.tintColor = tinColor ?? UIColor.black
return navButton
}

// MARK: - Actions
func actionTouchBtnBack() {
_ = self.navigationController?.popViewController(animated: true)
}

func actionTouchBtnLeft() {
}

func actionTouchBtnRight() {
}

// MARK: - Call Api

// MARK: - Functions

}
55 changes: 55 additions & 0 deletions BaseMVC/Sources/Controllers/StartViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import UIKit

class StartViewController: BaseViewController {

// MARK: - IBOutlet

@IBOutlet weak var tableView: UITableView!

// MARK: - Varialbes

// MARK: - View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

// check app
self.checkApp()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// MARK: - Navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}

// MARK: - Setup View

// MARK: - Actions

// MARK: - Call Api

// MARK: - Functions
private func checkApp() {
}

func gotoMainApp() {

}
}
29 changes: 29 additions & 0 deletions BaseMVC/Sources/Extensions/Color+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import UIKit

extension UIColor {

static func colorWith(red: Float, green: Float, blue: Float) -> UIColor {
return UIColor(colorLiteralRed: red / Float(255.0), green: green / Float(255.0), blue: blue / Float(255.0), alpha: 1.0)
}

convenience init(hex: String) {
let scanner = Scanner(string: hex)
scanner.scanLocation = 0
var rgbValue: UInt64 = 0
scanner.scanHexInt64(&rgbValue)
let r = (rgbValue & 0xff0000) >> 16
let g = (rgbValue & 0xff00) >> 8
let b = rgbValue & 0xff
self.init(red: CGFloat(r) / 0xff, green: CGFloat(g) / 0xff, blue: CGFloat(b) / 0xff, alpha: 1.0)
}

var toHexString: String {
var r: CGFloat = 0
var g: CGFloat = 0
var b: CGFloat = 0
var a: CGFloat = 0
self.getRed(&r, green: &g, blue: &b, alpha: &a)
// return
return String(format: "%02X%02X%02X", Int(r * 0xff), Int(g * 0xff), Int(b * 0xff))
}
}
Loading

0 comments on commit 6339a74

Please sign in to comment.