diff --git a/Example UICollectionView/ViewController.swift b/Example UICollectionView/ViewController.swift index bf480feb..900f4cf0 100644 --- a/Example UICollectionView/ViewController.swift +++ b/Example UICollectionView/ViewController.swift @@ -36,7 +36,7 @@ class ViewController: UIViewController { didSet { colorSelectedView.layer.cornerRadius = 5 colorSelectedView.layer.masksToBounds = true - colorSelectedView.backgroundColor = SkeletonDefaultConfig.tintColor + colorSelectedView.backgroundColor = SkeletonConfig.shared.tintColor } } diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 06a7ac92..56ac07e4 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -29,7 +29,7 @@ class ViewController: UIViewController { didSet { colorSelectedView.layer.cornerRadius = 5 colorSelectedView.layer.masksToBounds = true - colorSelectedView.backgroundColor = SkeletonDefaultConfig.tintColor + colorSelectedView.backgroundColor = SkeletonConfig.shared.tintColor } } diff --git a/SkeletonView.xcodeproj/project.pbxproj b/SkeletonView.xcodeproj/project.pbxproj index e077da1f..cadfd6b8 100644 --- a/SkeletonView.xcodeproj/project.pbxproj +++ b/SkeletonView.xcodeproj/project.pbxproj @@ -518,7 +518,6 @@ }; 52D6D97B1BEFF229002C0205 = { CreatedOnToolsVersion = 7.1; - DevelopmentTeam = KWEMDK92F4; LastSwiftMigration = 0800; }; F5F899F11FABA607002E8FDA = { @@ -951,7 +950,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = KWEMDK92F4; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -976,7 +975,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = KWEMDK92F4; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; diff --git a/Sources/Extensions/CALayer+Extensions.swift b/Sources/Extensions/CALayer+Extensions.swift index 43f736e5..d99b909c 100644 --- a/Sources/Extensions/CALayer+Extensions.swift +++ b/Sources/Extensions/CALayer+Extensions.swift @@ -51,7 +51,7 @@ extension CALayer { } private func calculateNumLines(maxLines: Int) -> Int { - let spaceRequitedForEachLine = SkeletonDefaultConfig.multilineHeight + SkeletonDefaultConfig.multilineSpacing + let spaceRequitedForEachLine = SkeletonConfig.shared.multilineHeight + SkeletonConfig.shared.multilineSpacing var numberOfSublayers = Int(round(CGFloat(bounds.height)/CGFloat(spaceRequitedForEachLine))) if maxLines != 0, maxLines <= numberOfSublayers { numberOfSublayers = maxLines } return numberOfSublayers diff --git a/Sources/Helpers/ContainsMultilineText.swift b/Sources/Helpers/ContainsMultilineText.swift index d3b63a22..777c921a 100644 --- a/Sources/Helpers/ContainsMultilineText.swift +++ b/Sources/Helpers/ContainsMultilineText.swift @@ -59,11 +59,11 @@ extension UILabel: ContainsMultilineText { } var lastLineFillingPercent: Int { - get { return objc_getAssociatedObject(self, &AssociatedKeys.lastLineFillingPercent) as? Int ?? SkeletonDefaultConfig.multilineLastLineFillPercent } + get { return objc_getAssociatedObject(self, &AssociatedKeys.lastLineFillingPercent) as? Int ?? SkeletonConfig.shared.multilineLastLineFillPercent } set { objc_setAssociatedObject(self, &AssociatedKeys.lastLineFillingPercent, newValue, AssociationPolicy.retain.objc) } } var multilineCornerRadius: Int { - get { return objc_getAssociatedObject(self, &AssociatedKeys.multilineCornerRadius) as? Int ?? SkeletonDefaultConfig.multilineCornerRadius } + get { return objc_getAssociatedObject(self, &AssociatedKeys.multilineCornerRadius) as? Int ?? SkeletonConfig.shared.multilineCornerRadius } set { objc_setAssociatedObject(self, &AssociatedKeys.multilineCornerRadius, newValue, AssociationPolicy.retain.objc) } } @@ -71,12 +71,12 @@ extension UILabel: ContainsMultilineText { extension UITextView: ContainsMultilineText { var lastLineFillingPercent: Int { - get { return objc_getAssociatedObject(self, &AssociatedKeys.lastLineFillingPercent) as? Int ?? SkeletonDefaultConfig.multilineLastLineFillPercent } + get { return objc_getAssociatedObject(self, &AssociatedKeys.lastLineFillingPercent) as? Int ?? SkeletonConfig.shared.multilineLastLineFillPercent } set { objc_setAssociatedObject(self, &AssociatedKeys.lastLineFillingPercent, newValue, AssociationPolicy.retain.objc) } } var multilineCornerRadius: Int { - get { return objc_getAssociatedObject(self, &AssociatedKeys.multilineCornerRadius) as? Int ?? SkeletonDefaultConfig.multilineCornerRadius } + get { return objc_getAssociatedObject(self, &AssociatedKeys.multilineCornerRadius) as? Int ?? SkeletonConfig.shared.multilineCornerRadius } set { objc_setAssociatedObject(self, &AssociatedKeys.multilineCornerRadius, newValue, AssociationPolicy.retain.objc) } } } diff --git a/Sources/SkeletonDefaultConfig.swift b/Sources/SkeletonDefaultConfig.swift index 0c130fd1..639eb223 100644 --- a/Sources/SkeletonDefaultConfig.swift +++ b/Sources/SkeletonDefaultConfig.swift @@ -1,5 +1,5 @@ // -// SkeletonDefaultConfig.swift +// SkeletonConfig.shared.swift // SkeletonView-iOS // // Created by Juanpe Catalán on 06/11/2017. @@ -8,17 +8,30 @@ import UIKit -public enum SkeletonDefaultConfig { - - public static let tintColor = UIColor.clouds - - public static let gradient = SkeletonGradient(baseColor: tintColor) - - public static let multilineHeight: CGFloat = 15 - - public static let multilineSpacing: CGFloat = 10 - - public static let multilineLastLineFillPercent = 70 - - public static let multilineCornerRadius = 0 +public struct SkeletonConfig { + + // MARK: - Defaults + + public static var shared = SkeletonConfig( + tintColor: .clouds, + gradient: SkeletonGradient(baseColor: .clouds), + multilineHeight: 15, + multilineSpacing: 10, + multilineLastLineFillPercent: 70, + multilineCornerRadius: 0 + ) + + // MARK: - Properties + + public var tintColor: UIColor + + public var gradient: SkeletonGradient + + public var multilineHeight: CGFloat + + public var multilineSpacing: CGFloat + + public var multilineLastLineFillPercent: Int + + public var multilineCornerRadius: Int } diff --git a/Sources/SkeletonLayer.swift b/Sources/SkeletonLayer.swift index 2125f38e..7f1310fe 100644 --- a/Sources/SkeletonLayer.swift +++ b/Sources/SkeletonLayer.swift @@ -15,11 +15,11 @@ class SkeletonLayerFactory { } func makeMultilineLayer(withType type: SkeletonType, for index: Int, width: CGFloat, multilineCornerRadius: Int) -> CALayer { - let spaceRequiredForEachLine = SkeletonDefaultConfig.multilineHeight + SkeletonDefaultConfig.multilineSpacing + let spaceRequiredForEachLine = SkeletonConfig.shared.multilineHeight + SkeletonConfig.shared.multilineSpacing let layer = type.layer layer.anchorPoint = .zero layer.name = CALayer.skeletonSubLayersName - layer.frame = CGRect(x: 0.0, y: CGFloat(index) * spaceRequiredForEachLine, width: width, height: SkeletonDefaultConfig.multilineHeight) + layer.frame = CGRect(x: 0.0, y: CGFloat(index) * spaceRequiredForEachLine, width: width, height: SkeletonConfig.shared.multilineHeight) layer.cornerRadius = CGFloat(multilineCornerRadius) layer.masksToBounds = true diff --git a/Sources/SkeletonView.swift b/Sources/SkeletonView.swift index ea52fdd5..8694f674 100644 --- a/Sources/SkeletonView.swift +++ b/Sources/SkeletonView.swift @@ -10,19 +10,19 @@ import UIKit public extension UIView { - func showSkeleton(usingColor color: UIColor = SkeletonDefaultConfig.tintColor) { + func showSkeleton(usingColor color: UIColor = SkeletonConfig.shared.tintColor) { showSkeleton(withType: .solid, usingColors: [color]) } - func showGradientSkeleton(usingGradient gradient: SkeletonGradient = SkeletonDefaultConfig.gradient) { + func showGradientSkeleton(usingGradient gradient: SkeletonGradient = SkeletonConfig.shared.gradient) { showSkeleton(withType: .gradient, usingColors: gradient.colors) } - func showAnimatedSkeleton(usingColor color: UIColor = SkeletonDefaultConfig.tintColor, animation: SkeletonLayerAnimation? = nil) { + func showAnimatedSkeleton(usingColor color: UIColor = SkeletonConfig.shared.tintColor, animation: SkeletonLayerAnimation? = nil) { showSkeleton(withType: .solid, usingColors: [color], animated: true, animation: animation) } - func showAnimatedGradientSkeleton(usingGradient gradient: SkeletonGradient = SkeletonDefaultConfig.gradient, animation: SkeletonLayerAnimation? = nil) { + func showAnimatedGradientSkeleton(usingGradient gradient: SkeletonGradient = SkeletonConfig.shared.gradient, animation: SkeletonLayerAnimation? = nil) { showSkeleton(withType: .gradient, usingColors: gradient.colors, animated: true, animation: animation) }