Skip to content

Commit

Permalink
Added extensions to the project
Browse files Browse the repository at this point in the history
  • Loading branch information
jogendra committed Apr 1, 2018
1 parent f64c5d4 commit a593c7d
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Phimpme.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
40688BF42067F1D1005428C2 /* ControllerConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40688BF32067F1D1005428C2 /* ControllerConstants.swift */; };
406A8ACD206FCFBE0094BA9A /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 406A8ACC206FCFBE0094BA9A /* SettingsViewController.swift */; };
406A8ACF2070BA2D0094BA9A /* Toast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 406A8ACE2070BA2D0094BA9A /* Toast.swift */; };
406A8AD12070D7FA0094BA9A /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 406A8AD02070D7FA0094BA9A /* Extensions.swift */; };
408F1A0720596AC500BDC313 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 408F1A0620596AC500BDC313 /* AppDelegate.swift */; };
408F1A0920596AC500BDC313 /* GalleryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 408F1A0820596AC500BDC313 /* GalleryViewController.swift */; };
408F1A0C20596AC500BDC313 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 408F1A0A20596AC500BDC313 /* Main.storyboard */; };
Expand All @@ -28,6 +29,7 @@
40688BF32067F1D1005428C2 /* ControllerConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ControllerConstants.swift; sourceTree = "<group>"; };
406A8ACC206FCFBE0094BA9A /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
406A8ACE2070BA2D0094BA9A /* Toast.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toast.swift; sourceTree = "<group>"; };
406A8AD02070D7FA0094BA9A /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
408F1A0320596AC500BDC313 /* Phimpme.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Phimpme.app; sourceTree = BUILT_PRODUCTS_DIR; };
408F1A0620596AC500BDC313 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
408F1A0820596AC500BDC313 /* GalleryViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -67,6 +69,7 @@
children = (
40688BF32067F1D1005428C2 /* ControllerConstants.swift */,
406A8ACE2070BA2D0094BA9A /* Toast.swift */,
406A8AD02070D7FA0094BA9A /* Extensions.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -283,6 +286,7 @@
40F899B9206137B600471ADF /* CameraViewController.swift in Sources */,
400167D52063AF82003EBAE4 /* MainTabBarViewController.swift in Sources */,
40688BF42067F1D1005428C2 /* ControllerConstants.swift in Sources */,
406A8AD12070D7FA0094BA9A /* Extensions.swift in Sources */,
40F899B72060F83700471ADF /* AccountsTableViewController.swift in Sources */,
408F1A0720596AC500BDC313 /* AppDelegate.swift in Sources */,
406A8ACF2070BA2D0094BA9A /* Toast.swift in Sources */,
Expand Down
5 changes: 3 additions & 2 deletions Phimpme/Controllers/GalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class GalleryViewController: UIViewController {
}

@IBAction func didTapSettingsMenu(_ sender: Any) {
let settingsStoryboard = UIStoryboard(name: "Main", bundle: nil)
let settingsViewController = settingsStoryboard.instantiateViewController(withIdentifier: "settingsVC")
guard let settingsViewController = UIStoryboard.settingsVC() as? SettingsViewController else {
return
}
if let navigation = navigationController {
navigation.pushViewController(settingsViewController, animated: true)
}
Expand Down
158 changes: 158 additions & 0 deletions Phimpme/Helpers/Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
//
// Extensions.swift
// Phimpme
//
// Created by JOGENDRA on 01/04/18.
// Copyright © 2018 Jogendra Singh. All rights reserved.
//

import Foundation
import UIKit

extension UIStoryboard {

class func mainStoryboard() -> UIStoryboard { return UIStoryboard(name: "Main", bundle: Bundle.main) }

class func initialVC() -> UIViewController {
return mainStoryboard().instantiateViewController(withIdentifier: "InitialViewController")
}

class func settingsVC() -> UIViewController {
return mainStoryboard().instantiateViewController(withIdentifier: "SettingsViewController")
}
}

extension UIApplication {

class func topViewController(_ base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
if let nav = base as? UINavigationController {
return topViewController(nav.visibleViewController)
}
if let tab = base as? UITabBarController {
if let selected = tab.selectedViewController {
return topViewController(selected)
}
}
if let presented = base?.presentedViewController {
return topViewController(presented)
}
return base
}
}


extension UIViewController {
func hideKeyboardWhenTappedAround() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
view.addGestureRecognizer(tap)
}

@objc func dismissKeyboard() {
view.endEditing(true)
}
}

extension UIButton {
func centerTextAndImage(spacing: CGFloat) {
let insetAmount = spacing / 2
imageEdgeInsets = UIEdgeInsets(top: 0, left: -insetAmount, bottom: 0, right: insetAmount)
titleEdgeInsets = UIEdgeInsets(top: 0, left: insetAmount, bottom: 0, right: -insetAmount)
contentEdgeInsets = UIEdgeInsets(top: 0, left: insetAmount, bottom: 0, right: insetAmount)
}

func verticleAlignTextAndImage(withSpacing spacing: CGFloat) {
let titleSize = titleLabel!.frame.size
let imageSize = imageView!.frame.size

titleEdgeInsets = UIEdgeInsets(top: 0, left: -imageSize.width, bottom: -(imageSize.height + spacing), right: 0)
imageEdgeInsets = UIEdgeInsets(top: -(titleSize.height + spacing), left: -imageSize.width/2, bottom: 0, right: -titleSize.width)
}

func leftAlignedTextAndImage(spacing: CGFloat) {
let insetAmount = spacing / 2
imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: insetAmount)
titleEdgeInsets = UIEdgeInsets(top: 0, left: insetAmount, bottom: 0, right: 0)
contentEdgeInsets = UIEdgeInsets(top: 0, left: insetAmount, bottom: 0, right: insetAmount)
}
}

extension UIColor {

class var appThemeColor: UIColor {
return UIColor(rgb: 0x007ED0)
}

class var toastGreen: UIColor {
return UIColor(rgb: 0x0C743B)
}
class var toastGray: UIColor {
return UIColor(rgb: 0xAAAAAA)
}

class var grayText: UIColor {
return UIColor(rgb: 0x111111)
}

class var grayLight: UIColor {
return UIColor(rgb: 0xcacaca)
}

class var appWarmGrey: UIColor {
return UIColor(white: 155.0 / 255.0, alpha: 1.0)
}

class var appLighterWarmGrey: UIColor {
return UIColor(white: 151.0 / 255.0, alpha: 1.0)
}

class var appGreyishBrown: UIColor {
return UIColor(white: 74.0 / 255.0, alpha: 1.0)
}

class var appWhiteButNot: UIColor {
return UIColor(red: 234.0 / 255.0, green: 233.0 / 255.0, blue: 233.0 / 255.0, alpha: 1.0)
}

class var iosRed: UIColor {
return UIColor(red: 255/255, green: 59/255, blue: 48/255, alpha: 1.0)
}

class var iosOrange: UIColor {
return UIColor(red: 255/255, green: 149/255, blue: 0/255, alpha: 1.0)
}

class var iosYellow: UIColor {
return UIColor(red: 255/255, green: 204/255, blue: 0/255, alpha: 1.0)
}

class var iosGreen: UIColor {
return UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1.0)
}

class var iosTealBlue: UIColor {
return UIColor(red: 90/255, green: 200/255, blue: 250/255, alpha: 1.0)
}

class var iosBlue: UIColor {
return UIColor(red: 0/255, green: 122/255, blue: 255/255, alpha: 1.0)
}

class var iosPurple: UIColor {
return UIColor(red: 88/255, green: 66/255, blue: 214/255, alpha: 1.0)
}

class var iosPink: UIColor {
return UIColor(red: 255/255, green: 45/255, blue: 85/255, alpha: 1.0)
}


convenience init(rgb: UInt) {
self.init(
red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgb & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}

}
2 changes: 1 addition & 1 deletion Phimpme/Storyboards/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<!--Settings-->
<scene sceneID="9Da-h7-nOB">
<objects>
<tableViewController storyboardIdentifier="settingsVC" useStoryboardIdentifierAsRestorationIdentifier="YES" id="vJg-oZ-rHb" customClass="SettingsViewController" customModule="Phimpme" customModuleProvider="target" sceneMemberID="viewController">
<tableViewController storyboardIdentifier="SettingsViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="vJg-oZ-rHb" customClass="SettingsViewController" customModule="Phimpme" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="5yt-7z-KEq">
<rect key="frame" x="0.0" y="0.0" width="375" height="603"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down

0 comments on commit a593c7d

Please sign in to comment.