Skip to content

Commit

Permalink
Merge pull request #1 from reececomo/83-Customisable-Defaults
Browse files Browse the repository at this point in the history
Juanpe#83 Customisable Defaults
  • Loading branch information
reececomo authored Aug 2, 2018
2 parents 2fe2323 + af91af3 commit 0eff052
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Example UICollectionView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
5 changes: 2 additions & 3 deletions SkeletonView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@
};
52D6D97B1BEFF229002C0205 = {
CreatedOnToolsVersion = 7.1;
DevelopmentTeam = KWEMDK92F4;
LastSwiftMigration = 0800;
};
F5F899F11FABA607002E8FDA = {
Expand Down Expand Up @@ -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";
Expand All @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion Sources/Extensions/CALayer+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Sources/Helpers/ContainsMultilineText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,24 @@ 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) }
}

}
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) }
}
}
41 changes: 27 additions & 14 deletions Sources/SkeletonDefaultConfig.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// SkeletonDefaultConfig.swift
// SkeletonConfig.shared.swift
// SkeletonView-iOS
//
// Created by Juanpe Catalán on 06/11/2017.
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions Sources/SkeletonLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Sources/SkeletonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 0eff052

Please sign in to comment.