Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- update to swift 3.1 #1

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion AppearanceNavigationController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0830;
ORGANIZATIONNAME = Zen;
TargetAttributes = {
ADF894961BE0D3C800C35CAC = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0820;
};
};
};
Expand Down Expand Up @@ -223,8 +224,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -267,8 +270,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -287,6 +292,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -299,6 +305,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.yalantis.AppearanceNavigationController;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -310,6 +317,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.yalantis.AppearanceNavigationController;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion AppearanceNavigationController/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return true
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -14,10 +18,9 @@
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
29 changes: 14 additions & 15 deletions AppearanceNavigationController/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="jaD-iT-bSD">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="jaD-iT-bSD">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Appearances-->
<scene sceneID="Mtc-Qy-oYS">
<objects>
<tableViewController id="LIk-eB-cvG" customClass="RootViewController" customModule="AppearanceNavigationController" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="FqX-GR-dP6">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="separatorColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="sectionIndexBackgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="separatorColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="sectionIndexBackgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" id="Bdi-il-fz6">
<rect key="frame" x="0.0" y="92" width="600" height="44"/>
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Bdi-il-fz6" id="DBz-SQ-U0f">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</tableViewCellContentView>
<animations/>
<connections>
<segue destination="kNY-7h-cRk" kind="show" id="3NO-S7-VtG"/>
</connections>
Expand All @@ -51,9 +52,8 @@
<viewControllerLayoutGuide type="bottom" id="GrP-Nr-VQ8"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="TBr-fr-ZKP">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
</view>
<toolbarItems>
Expand All @@ -75,7 +75,6 @@
<navigationBar key="navigationBar" contentMode="scaleToFill" id="a1G-B3-s9R">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</navigationBar>
<connections>
<segue destination="LIk-eB-cvG" kind="relationship" relationship="rootViewController" id="k0E-XR-pd8"/>
Expand Down
14 changes: 7 additions & 7 deletions AppearanceNavigationController/ContentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ContentViewController: UIViewController, NavigationControllerAppearanceCon
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

navigationItem.rightBarButtonItem = editButtonItem()
navigationItem.rightBarButtonItem = editButtonItem
}

var appearance: Appearance? {
Expand All @@ -18,21 +18,21 @@ class ContentViewController: UIViewController, NavigationControllerAppearanceCon

// mark: - Actions

override func setEditing(editing: Bool, animated: Bool) {
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)

setNeedsUpdateNavigationControllerAppearance()
}

// mark: - AppearanceNavigationControllerContent

func prefersNavigationControllerToolbarHidden(navigationController: UINavigationController) -> Bool {
func prefersNavigationControllerToolbarHidden(_ navigationController: UINavigationController) -> Bool {
// hide toolbar during editing
return editing
return isEditing
}

func preferredNavigationControllerAppearance(navigationController: UINavigationController) -> Appearance? {
func preferredNavigationControllerAppearance(_ navigationController: UINavigationController) -> Appearance? {
// inverse navigation bar color and status bar during editing
return editing ? appearance?.inverse() : appearance
return isEditing ? appearance?.inverse() : appearance
}
}
}
16 changes: 8 additions & 8 deletions AppearanceNavigationController/Misc/Appearance+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ extension Appearance {

let navigationBarColor = UIColor.randomColor()
value.navigationBar.backgroundColor = navigationBarColor
value.navigationBar.tintColor = navigationBarColor.isBright ? UIColor.blackColor() : UIColor.whiteColor()
value.navigationBar.tintColor = navigationBarColor.isBright ? UIColor.black : UIColor.white

let toolbarColor = UIColor.randomColor()
value.toolbar.backgroundColor = toolbarColor
value.toolbar.tintColor = toolbarColor.isBright ? UIColor.blackColor() : UIColor.whiteColor()
value.toolbar.tintColor = toolbarColor.isBright ? UIColor.black : UIColor.white

value.statusBarStyle = navigationBarColor.brightness > 0.5 ? .Default : .LightContent
value.statusBarStyle = navigationBarColor.brightness > 0.5 ? .default : .lightContent

return value
}
Expand All @@ -27,18 +27,18 @@ extension Appearance {
value.navigationBar.tintColor = navigationBar.tintColor.inverse()
value.toolbar.backgroundColor = toolbar.backgroundColor.inverse()
value.toolbar.tintColor = toolbar.tintColor.inverse()
value.statusBarStyle = value.navigationBar.backgroundColor.isBright ? .Default : .LightContent
value.statusBarStyle = value.navigationBar.backgroundColor.isBright ? .default : .lightContent

return value
}

static let lightAppearance: Appearance = {
var value = Appearance()

value.navigationBar.backgroundColor = UIColor.lightGrayColor()
value.navigationBar.tintColor = UIColor.whiteColor()
value.statusBarStyle = .LightContent
value.navigationBar.backgroundColor = UIColor.lightGray
value.navigationBar.tintColor = UIColor.white
value.statusBarStyle = .lightContent

return value
}()
}
}
10 changes: 5 additions & 5 deletions AppearanceNavigationController/Misc/ImageRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import UIKit

class ImageRenderer: NSObject {

class func renderImageOfColor(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) -> UIImage {
class func renderImageOfColor(_ color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) -> UIImage {
UIGraphicsBeginImageContext(size);
let context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, CGRect(x:0, y:0, width: size.width, height: size.height));
context?.setFillColor(color.cgColor);
context?.fill(CGRect(x:0, y:0, width: size.width, height: size.height));

let output = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return output;
return output!;
}
}
}
18 changes: 7 additions & 11 deletions AppearanceNavigationController/Misc/UIColor+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ extension UIColor {

// used solution from http://stackoverflow.com/a/29806108/4405316
var brightness: CGFloat {
let colorSpace = CGColorGetColorSpace(CGColor)
let colorSpaceModel = CGColorSpaceGetModel(colorSpace)

var brightness: CGFloat = 0.0
if colorSpaceModel == .RGB {
let components = CGColorGetComponents(CGColor)
brightness = ((components[0] * 299) + (components[1] * 587) + (components[2] * 114)) / 1000
} else {
getWhite(&brightness, alpha: nil)
}

guard let components = cgColor.components else { return brightness }
let redBrightness = components[0] * 299
let greenBrightness = components[1] * 587
let blueBrightness = components[2] * 114
brightness = (redBrightness + greenBrightness + blueBrightness) / 1000

return brightness
}

Expand All @@ -42,4 +38,4 @@ extension UIColor {
alpha: CGFloat(arc4random_uniform(100)) / 100
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ public struct Appearance: Equatable {

public struct Bar: Equatable {

var style: UIBarStyle = .Default
var style: UIBarStyle = .default
var backgroundColor = UIColor(red: 234 / 255, green: 46 / 255, blue: 73 / 255, alpha: 1)
var tintColor = UIColor.whiteColor()
var tintColor = UIColor.white
var barTintColor: UIColor?
}

var statusBarStyle: UIStatusBarStyle = .Default
var statusBarStyle: UIStatusBarStyle = .default
var navigationBar = Bar()
var toolbar = Bar()
}
Expand All @@ -27,4 +27,4 @@ public func ==(lhs: Appearance.Bar, rhs: Appearance.Bar) -> Bool {

public func ==(lhs: Appearance, rhs: Appearance) -> Bool {
return lhs.statusBarStyle == rhs.statusBarStyle && lhs.navigationBar == rhs.navigationBar && lhs.toolbar == rhs.toolbar
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ import Foundation
import UIKit
import QuartzCore

public class AppearanceApplyingStrategy {
open class AppearanceApplyingStrategy {

public func apply(appearance: Appearance?, toNavigationController navigationController: UINavigationController, animated: Bool) {
open func apply(_ appearance: Appearance?, toNavigationController navigationController: UINavigationController, animated: Bool) {
if let appearance = appearance {
let navigationBar = navigationController.navigationBar
let toolbar = navigationController.toolbar

if !navigationController.navigationBarHidden {
if !navigationController.isNavigationBarHidden {
let background = ImageRenderer.renderImageOfColor(appearance.navigationBar.backgroundColor)
navigationBar.setBackgroundImage(background, forBarMetrics: .Default)
navigationBar.setBackgroundImage(background, for: .default)
navigationBar.tintColor = appearance.navigationBar.tintColor
navigationBar.barTintColor = appearance.navigationBar.barTintColor
navigationBar.titleTextAttributes = [
NSForegroundColorAttributeName: appearance.navigationBar.tintColor
]
}

if !navigationController.toolbarHidden {
toolbar.setBackgroundImage(
if !navigationController.isToolbarHidden {
toolbar?.setBackgroundImage(
ImageRenderer.renderImageOfColor(appearance.toolbar.backgroundColor),
forToolbarPosition: .Any,
barMetrics: .Default
forToolbarPosition: .any,
barMetrics: .default
)
toolbar.tintColor = appearance.toolbar.tintColor
toolbar.barTintColor = appearance.toolbar.barTintColor
toolbar?.tintColor = appearance.toolbar.tintColor
toolbar?.barTintColor = appearance.toolbar.barTintColor
}
}
}
}
}
Loading