diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..adb93af --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2015 Tonic Design Co. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/StyleKit.podspec b/StyleKit.podspec new file mode 100644 index 0000000..78f4ac9 --- /dev/null +++ b/StyleKit.podspec @@ -0,0 +1,12 @@ +Pod::Spec.new do |s| + s.name = "StyleKit" + s.version = "2.1.3" + s.license = { :type => "MIT", :file => "LICENSE" } + s.summary = "StyleKit is an iOS library that styles native controls with a CSS-like JSON format." + s.homepage = "https://github.com/dmgctrl/StyleKit" + s.author = "Tonic Design Co." + s.platform = :ios, "9.0" + s.source = { :git => "https://github.com/dmgctrl/StyleKit.git", :tag => "#{s.version}" } + s.source_files = "StyleKit/StyleKit/**/*.swift" + s.swift_version = "4.2" +end diff --git a/StyleKit/StyleKit.xcodeproj/project.pbxproj b/StyleKit/StyleKit.xcodeproj/project.pbxproj index 5e4eb9d..4e5f14d 100644 --- a/StyleKit/StyleKit.xcodeproj/project.pbxproj +++ b/StyleKit/StyleKit.xcodeproj/project.pbxproj @@ -205,17 +205,17 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0800; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 0930; ORGANIZATIONNAME = "Tonic Design"; TargetAttributes = { 29B64EFB1DC39E0100D460B1 = { CreatedOnToolsVersion = 8.0; - LastSwiftMigration = 0900; + LastSwiftMigration = 1010; ProvisioningStyle = Automatic; }; 29B64F031DC39E0100D460B1 = { CreatedOnToolsVersion = 8.0; - LastSwiftMigration = 0900; + LastSwiftMigration = 1010; ProvisioningStyle = Automatic; }; }; @@ -319,12 +319,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 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_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -356,7 +358,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -372,12 +374,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 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_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -402,7 +406,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 4.2; VALIDATE_PRODUCT = YES; }; name = Release; @@ -421,6 +425,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_BITCODE = NO; INFOPLIST_FILE = StyleKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; @@ -429,8 +434,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -451,6 +455,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_BITCODE = NO; INFOPLIST_FILE = StyleKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; @@ -458,8 +463,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.tonicdesign.StyleKit; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -482,8 +486,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.tonicdesign.StyleKitTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -502,8 +505,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tonicdesign.StyleKitTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/StyleKit/StyleKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/StyleKit/StyleKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/StyleKit/StyleKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/StyleKit/StyleKit.xcodeproj/xcshareddata/xcschemes/StyleKit.xcscheme b/StyleKit/StyleKit.xcodeproj/xcshareddata/xcschemes/StyleKit.xcscheme index b508b59..a3f21e8 100644 --- a/StyleKit/StyleKit.xcodeproj/xcshareddata/xcschemes/StyleKit.xcscheme +++ b/StyleKit/StyleKit.xcodeproj/xcshareddata/xcschemes/StyleKit.xcscheme @@ -1,6 +1,6 @@ - NSAppTransportSecurity - - NSAllowsArbitraryLoads - - CFBundleDevelopmentRegion en CFBundleExecutable @@ -20,13 +15,27 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + 2.1.3 CFBundleSignature ???? CFBundleVersion 1 LSRequiresIPhoneOS + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + UIAppFonts + + Brandon_thin.otf + Brandon_med.otf + Brandon_light.otf + Brandon_light_it.otf + Brandon_blk.otf + Brandon_bld.otf + UILaunchStoryboardName LaunchScreen UIMainStoryboardFile @@ -41,14 +50,5 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - UIAppFonts - - Brandon_thin.otf - Brandon_med.otf - Brandon_light.otf - Brandon_light_it.otf - Brandon_blk.otf - Brandon_bld.otf - diff --git a/StyleKit/StyleKit/LabelStylist.swift b/StyleKit/StyleKit/LabelStylist.swift index 7fc1088..7e4daaa 100644 --- a/StyleKit/StyleKit/LabelStylist.swift +++ b/StyleKit/StyleKit/LabelStylist.swift @@ -23,18 +23,18 @@ class LabelStyle: Stylist { "Justified":.justified, "Natural":.natural] - static func attributesForLabel(_ styles:AttributedTextStyle, textAlignment:NSTextAlignment) -> Dictionary { + static func attributesForLabel(_ styles:AttributedTextStyle, textAlignment:NSTextAlignment) -> Dictionary { - var attributes:[NSAttributedStringKey: AnyObject] = [:] + var attributes:[NSAttributedString.Key: AnyObject] = [:] if let fontName = styles.fontStyle?.fontName, let fontSize = styles.fontStyle?.size { - attributes[NSAttributedStringKey.font] = UIFont(name: fontName, size: CGFloat(fontSize)) + attributes[NSAttributedString.Key.font] = UIFont(name: fontName, size: CGFloat(fontSize)) } if let tracking = styles.tracking, let fontSize = styles.fontStyle?.size { let characterSpacing = fontSize * tracking / 1000 - attributes[NSAttributedStringKey.kern] = characterSpacing as AnyObject? + attributes[NSAttributedString.Key.kern] = characterSpacing as AnyObject? } let style = NSMutableParagraphStyle() @@ -48,7 +48,7 @@ class LabelStyle: Stylist { if let lineSpace = styles.lineSpacing { style.lineSpacing = lineSpace } - attributes[NSAttributedStringKey.paragraphStyle] = style + attributes[NSAttributedString.Key.paragraphStyle] = style return attributes } diff --git a/StyleKit/StyleKit/ProgressViewStylist.swift b/StyleKit/StyleKit/ProgressViewStylist.swift index 89cab10..d42a3a0 100644 --- a/StyleKit/StyleKit/ProgressViewStylist.swift +++ b/StyleKit/StyleKit/ProgressViewStylist.swift @@ -6,7 +6,7 @@ class ProgressViewStyle : Stylist { typealias Element = UIProgressView - var style: UIProgressViewStyle? + var style: UIProgressView.Style? var progressTintColor: UIColor? var trackTintColor: UIColor? var progressImage: UIImage? @@ -31,7 +31,7 @@ class ProgressViewStyle : Stylist { } switch property { case .Style: - if let theValue = value as? Int, let viewStyle = UIProgressViewStyle(rawValue: theValue) { + if let theValue = value as? Int, let viewStyle = UIProgressView.Style(rawValue: theValue) { style.style = viewStyle } case .ProgressTintColor: diff --git a/StyleKit/StyleKit/SegmentedControlStylist.swift b/StyleKit/StyleKit/SegmentedControlStylist.swift index b1dd2f5..d794918 100644 --- a/StyleKit/StyleKit/SegmentedControlStylist.swift +++ b/StyleKit/StyleKit/SegmentedControlStylist.swift @@ -84,8 +84,8 @@ extension UISegmentedControl { case .FontStyle: if let fontStyle = style.fontStyle { let font = UIFont(name: fontStyle.fontName, size: CGFloat(fontStyle.size)) - normalAttributes[NSAttributedStringKey.font] = font - selectedAttributes[NSAttributedStringKey.font] = font + normalAttributes[NSAttributedString.Key.font] = font + selectedAttributes[NSAttributedString.Key.font] = font } case .TintColor: if let tintColor = style.tintColor { @@ -115,12 +115,12 @@ extension UISegmentedControl { } } - func assignColors(_ colors: ColorStyle, forState state: UIControlState, resources:CommonResources) { + func assignColors(_ colors: ColorStyle, forState state: UIControl.State, resources:CommonResources) { if let colorKey = colors.backgroundColor, let color = resources.colors[colorKey] { self.setBackgroundImage(UIImage.imageWithColor(color), for: state, barMetrics: .default) } if let colorKey = colors.textColor, let color = resources.colors[colorKey] { - let attributes = [NSAttributedStringKey.foregroundColor: color] + let attributes = [NSAttributedString.Key.foregroundColor: color] self.setTitleTextAttributes(attributes, for: state) } } diff --git a/StyleKit/StyleKit/StepperStylist.swift b/StyleKit/StyleKit/StepperStylist.swift index 5973f24..268bd54 100644 --- a/StyleKit/StyleKit/StepperStylist.swift +++ b/StyleKit/StyleKit/StepperStylist.swift @@ -24,12 +24,12 @@ class StepperStyle : Stylist { case Disabled = "disabledState" } - static func controlStateForAllowedState(_ state:AllowedStates) -> UIControlState { + static func controlStateForAllowedState(_ state:AllowedStates) -> UIControl.State { switch state { case .Disabled: - return UIControlState.disabled + return UIControl.State.disabled case .Highlighted: - return UIControlState.highlighted + return UIControl.State.highlighted case .Normal: return .normal } diff --git a/StyleKit/StyleKit/Style.swift b/StyleKit/StyleKit/Style.swift index 3ef8420..67d3421 100644 --- a/StyleKit/StyleKit/Style.swift +++ b/StyleKit/StyleKit/Style.swift @@ -87,10 +87,10 @@ open class Style { case invalidLabelStyle } - open static let sharedInstance = Style() + public static let sharedInstance = Style() fileprivate let fileName = "Style.json" - open static let styleSheetLocationKey = "SKStylesheetLocation" // Make sure to update docs if this changes + public static let styleSheetLocationKey = "SKStylesheetLocation" // Make sure to update docs if this changes open var resources = CommonResources() @@ -222,7 +222,7 @@ open class Style { } } - assert(false, "error serializing JSON: \(error)") + //assert(false, "error serializing JSON: \(error)") } } diff --git a/StyleKit/StyleKit/TextFieldStylist.swift b/StyleKit/StyleKit/TextFieldStylist.swift index 31a306e..d696663 100644 --- a/StyleKit/StyleKit/TextFieldStylist.swift +++ b/StyleKit/StyleKit/TextFieldStylist.swift @@ -12,7 +12,7 @@ class TextFieldStyle : Stylist { var borderWidth: Int? var cornerRadius: Int? var textAlignment: NSTextAlignment? - var borderStyle: UITextBorderStyle? + var borderStyle: UITextField.BorderStyle? var backgroundColor: UIColor? enum Properties: String { @@ -84,10 +84,10 @@ class TextFieldStyle : Stylist { return nil } - static func mapBorderStyle(_ styleStr:String) -> UITextBorderStyle? { + static func mapBorderStyle(_ styleStr:String) -> UITextField.BorderStyle? { let allowedValues = ["None","Line","Bezel","RoundedRect"] if let index = allowedValues.index(of: styleStr) { - return UITextBorderStyle(rawValue: index) + return UITextField.BorderStyle(rawValue: index) } return nil } diff --git a/StyleKit/StyleKit/TextViewStylist.swift b/StyleKit/StyleKit/TextViewStylist.swift index 60c72b1..fd06bc5 100644 --- a/StyleKit/StyleKit/TextViewStylist.swift +++ b/StyleKit/StyleKit/TextViewStylist.swift @@ -22,25 +22,25 @@ class TextViewStyle { "Justified":.justified, "Natural":.natural] - static func attributesForTextView(_ styles:AttributedTextStyle) -> Dictionary { + static func attributesForTextView(_ styles:AttributedTextStyle) -> Dictionary { let style = NSMutableParagraphStyle() style.alignment = NSTextAlignment.center if let lineSpace = styles.lineSpacing { style.lineSpacing = lineSpace } - var attributes:[NSAttributedStringKey: AnyObject] = [:] + var attributes:[NSAttributedString.Key: AnyObject] = [:] if let fontName = styles.fontStyle?.fontName, let fontSize = styles.fontStyle?.size { - attributes[NSAttributedStringKey.font] = UIFont(name: fontName, size: CGFloat(fontSize)) + attributes[NSAttributedString.Key.font] = UIFont(name: fontName, size: CGFloat(fontSize)) } if let tracking = styles.tracking, let fontSize = styles.fontStyle?.size { let characterSpacing = fontSize * tracking / 1000 - attributes[NSAttributedStringKey.kern] = characterSpacing as AnyObject? + attributes[NSAttributedString.Key.kern] = characterSpacing as AnyObject? } - attributes[NSAttributedStringKey.paragraphStyle] = style + attributes[NSAttributedString.Key.paragraphStyle] = style return attributes } diff --git a/StyleKit/StyleKit/Utils.swift b/StyleKit/StyleKit/Utils.swift index 8562e6e..b5b33bb 100644 --- a/StyleKit/StyleKit/Utils.swift +++ b/StyleKit/StyleKit/Utils.swift @@ -27,15 +27,15 @@ extension UIColor { extension String { /// Converts hex format `#123ABC` or `123ABC` to Int value func hexColorToInt() -> Int? { - guard dropPoundPrefix.characters.count == 6 else { return nil } + guard dropPoundPrefix.count == 6 else { return nil } return dropPoundPrefix.hexaToDecimal } } extension String { - var dropPoundPrefix: String { return hasPrefix("#") ? String(characters.dropFirst(1)) : self } - var drop0xPrefix: String { return hasPrefix("0x") ? String(characters.dropFirst(2)) : self } - var drop0bPrefix: String { return hasPrefix("0b") ? String(characters.dropFirst(2)) : self } + var dropPoundPrefix: String { return hasPrefix("#") ? String(self.dropFirst(1)) : self } + var drop0xPrefix: String { return hasPrefix("0x") ? String(self.dropFirst(2)) : self } + var drop0bPrefix: String { return hasPrefix("0b") ? String(self.dropFirst(2)) : self } var hexaToDecimal: Int { return Int(drop0xPrefix, radix: 16) ?? 0 } var hexaToBinaryString: String { return String(hexaToDecimal, radix: 2) } var decimalToHexaString: String { return String(Int(self) ?? 0, radix: 16) } @@ -52,7 +52,7 @@ extension Int { extension UIImage { class func imageWithColor(_ color: UIColor) -> UIImage { - let rect = CGRect(x: 0, y: 0, width: 0.5, height: 44.0) + let rect = CGRect(x: 0, y: 0, width: 1.0, height: 1.0) UIGraphicsBeginImageContext(rect.size) let context = UIGraphicsGetCurrentContext() context!.setFillColor(color.cgColor);