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

Eck separtate demo and framework code #39

Open
wants to merge 8 commits into
base: master
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

This file was deleted.

521 changes: 521 additions & 0 deletions StyleKit/StyleKit.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.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class ColorStyle {
}
}

class CommonResources {
var fontLabels = [String: String]()
var colors = [String: UIColor]()
var imageNames = [String: String]()
public class CommonResources {
public var fontLabels = [String: String]()
public var colors = [String: UIColor]()
public var imageNames = [String: String]()
}

class AttributedTextStyle {
Expand All @@ -41,7 +41,7 @@ protocol Stylist {
associatedtype Element
}

protocol StyleKitSubscriber: class {
public protocol StyleKitSubscriber: class {
func update()
}

Expand All @@ -50,7 +50,7 @@ enum FontProperty: String {
case size = "size"
}

enum UIElement: String {
public enum UIElement: String {
case segmentedControl = "SegmentedControls"
case textField = "TextFields"
case button = "Buttons"
Expand Down Expand Up @@ -78,24 +78,24 @@ enum ColorProperties: String {
}


class Style {
public class Style {

enum StyleKitError: ErrorType {
case StyleFileNotFound(String)
case InvalidTextFieldProperty
case InvalidLabelStyle
}

static let sharedInstance = Style()
public static let sharedInstance = Style()

private let fileName = "Style.json"
static let styleSheetLocation = "StyleKit-StylesheetLocation" // Make sure to update docs if this changes
public static let styleSheetLocationKey = "SKStylesheetLocation" // Make sure to update docs if this changes

var resources = CommonResources()
public var resources = CommonResources()

typealias StyleMap = [String: AnyObject]
public typealias StyleMap = [String: AnyObject]

var styleMap = [UIElement:StyleMap]()
public var styleMap = [UIElement:StyleMap]()

private let subscribers: NSHashTable

Expand All @@ -109,7 +109,7 @@ class Style {
}

private func getStylePath() throws -> NSURL {
if let string = NSBundle.mainBundle().infoDictionary?[Style.styleSheetLocation] as? String,
if let string = NSBundle.mainBundle().infoDictionary?[Style.styleSheetLocationKey] as? String,
documentDirectory = Utils.documentDirectory {
let pathURL: NSURL?
if string.containsString(".json") {
Expand Down Expand Up @@ -272,7 +272,7 @@ extension Style {

Call 'removeSubscriber(subscriber: StyleKitSubscriber)' to unregister
*/
func addSubscriber(subscriber: StyleKitSubscriber) {
public func addSubscriber(subscriber: StyleKitSubscriber) {
if !subscribers.containsObject(subscriber) {
subscribers.addObject(subscriber)
}
Expand All @@ -281,7 +281,7 @@ extension Style {
/**
Removes a subscriber from the list of subscribers
*/
func removeSubscriber(subscriber: StyleKitSubscriber) {
public func removeSubscriber(subscriber: StyleKitSubscriber) {
if subscribers.containsObject(subscriber) {
subscribers.removeObject(subscriber)
}
Expand All @@ -292,13 +292,13 @@ extension Style {

StyleKit.sharedInstance.refresh()

Since the bundle is readonly, the stylesheet must be at the location specified in the applications plist file for the key 'StyleKit-StylesheetLocation'. The new stylesheet will **not** automatically get applied to views which have already been tagged/styled. To restyle a view which has already been tagged/styled, call `style()` on the view.
Since the bundle is readonly, the stylesheet must be at the location specified in the applications plist file for the key 'SKStylesheetLocation'. The new stylesheet will **not** automatically get applied to views which have already been tagged/styled. To restyle a view which has already been tagged/styled, call `style()` on the view.

You may register for changes to the stylesheet by implementing the `StyleKitSubscriber` protocol and calling `addSubscriber`.

StyleKit.sharedInstance.addSubscriber(self)
*/
func refresh() {
public func refresh() {
serialize()
let enumerator = subscribers.objectEnumerator()
while let subscriber = enumerator.nextObject() as? StyleKitSubscriber {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

import UIKit

extension UIView {
public extension UIView {
private struct AssociatedKeys {
static var styleTag = ""
}

/**
Setting the styleTag automatically applies styles as defined in the stylesheet
*/
@IBInspectable var styleTag: String? {
@IBInspectable public var styleTag: String? {
get {
return objc_getAssociatedObject(self, &AssociatedKeys.styleTag) as? String
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import Foundation
import UIKit


struct Utils {
internal struct Utils {
static let documentDirectory = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).last
}


extension UIColor {
convenience init(red: Int, green: Int, blue: Int, alph: Float) {
assert(red >= 0 && red <= 255, "Invalid red component")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

}


struct Utils {
static let documentDirectory = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).last
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="y3g-6O-uUf">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--StyleKit Catalog-->
<!--StyleKitDemo Catalog-->
<scene sceneID="92v-eU-MGr">
<objects>
<tableViewController title="StyleKit Catalog" id="aYU-mY-bha" sceneMemberID="viewController">
<tableViewController title="StyleKitDemo Catalog" id="aYU-mY-bha" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="ciM-VT-zAy">
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand All @@ -22,11 +21,11 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="vS0-dj-m3H" id="3dP-4h-5ad">
<frame key="frameInset" width="375" height="43"/>
<frame key="frameInset" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Example #1" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="mOS-BD-XuF">
<frame key="frameInset" minX="15" width="345" height="43"/>
<frame key="frameInset" minX="15" width="345" height="43.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
Expand All @@ -42,11 +41,11 @@
<rect key="frame" x="0.0" y="44" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ikE-gz-QWB" id="5gg-qQ-mN0">
<frame key="frameInset" width="375" height="43"/>
<frame key="frameInset" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Styles Preview" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="VsT-pf-3sf">
<frame key="frameInset" minX="15" width="345" height="43"/>
<frame key="frameInset" minX="15" width="345" height="43.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
Expand All @@ -62,11 +61,11 @@
<rect key="frame" x="0.0" y="88" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="xgS-ga-LRm" id="Ccs-xH-TZj">
<frame key="frameInset" width="375" height="43"/>
<frame key="frameInset" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Reading" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="qlz-BO-OHo">
<frame key="frameInset" minX="15" width="345" height="43"/>
<frame key="frameInset" minX="15" width="345" height="43.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
Expand All @@ -86,7 +85,7 @@
<outlet property="delegate" destination="aYU-mY-bha" id="UQC-5b-DgB"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="StyleKit Catalog" id="gSS-cD-RHS">
<navigationItem key="navigationItem" title="StyleKitDemo Catalog" id="gSS-cD-RHS">
<barButtonItem key="backBarButtonItem" title="Catalog" id="D0M-FA-Fwe"/>
</navigationItem>
</tableViewController>
Expand Down Expand Up @@ -509,10 +508,10 @@ Sending out an S.O.S.</string>
</objects>
<point key="canvasLocation" x="1388" y="1352.473763118441"/>
</scene>
<!--StyleKit Catalog-->
<!--StyleKitDemo Catalog-->
<scene sceneID="Byg-9O-NQA">
<objects>
<navigationController title="StyleKit Catalog" automaticallyAdjustsScrollViewInsets="NO" id="y3g-6O-uUf" sceneMemberID="viewController">
<navigationController title="StyleKitDemo Catalog" automaticallyAdjustsScrollViewInsets="NO" id="y3g-6O-uUf" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" misplaced="YES" translucent="NO" id="Nno-YI-l6u">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
Expand All @@ -527,7 +526,7 @@ Sending out an S.O.S.</string>
</objects>
<point key="canvasLocation" x="129" y="493"/>
</scene>
<!--StyleKit-->
<!--StyleKitDemo-->
<scene sceneID="sbq-LV-NnS">
<objects>
<viewController id="qI1-q7-C7V" customClass="ViewController" customModule="StyleKitSample" customModuleProvider="target" sceneMemberID="viewController">
Expand Down Expand Up @@ -672,7 +671,7 @@ Sending out an S.O.S.</string>
<constraint firstItem="ba0-IN-AmL" firstAttribute="centerX" secondItem="oDo-30-HwC" secondAttribute="centerX" id="vqX-OT-8nL"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="StyleKit" id="cYX-Id-79P"/>
<navigationItem key="navigationItem" title="StyleKitDemo" id="cYX-Id-79P"/>
<connections>
<outlet property="button1" destination="dd8-Fy-1jk" id="VlJ-Sv-qMm"/>
</connections>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

import Foundation
import StyleKit

extension Utils {


static func copyStyleFileFromBundle() {

if let relativePath = NSBundle.mainBundle().infoDictionary?[Style.styleSheetLocation] as? String,
if let relativePath = NSBundle.mainBundle().infoDictionary?[Style.styleSheetLocationKey] as? String,
let srcDir = NSBundle.mainBundle().URLForResource("Style", withExtension: "json"),
let destDir = Utils.documentDirectory?.URLByAppendingPathComponent(relativePath) {
Utils.copyStyleFile(from: srcDir, to: destDir)
Expand Down Expand Up @@ -37,7 +38,7 @@ extension Utils {
}

static func downloadStyleFile() {
if let string = NSBundle.mainBundle().infoDictionary?[Style.styleSheetLocation] as? String {
if let string = NSBundle.mainBundle().infoDictionary?[Style.styleSheetLocationKey] as? String {
if let url = NSURL(string:"https://dl.dropboxusercontent.com/u/26582460/Style.json") {
NSURLSession.sharedSession().downloadTaskWithURL(url, completionHandler: { tempFileDirectory, response, error in
if error == nil {
Expand Down
54 changes: 54 additions & 0 deletions StyleKit/StyleKitDemo/StyleKit/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIAppFonts</key>
<array>
<string>Brandon_thin.otf</string>
<string>Brandon_med.otf</string>
<string>Brandon_light.otf</string>
<string>Brandon_light_it.otf</string>
<string>Brandon_blk.otf</string>
<string>Brandon_bld.otf</string>
</array>
<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>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
Loading