diff --git a/.gitignore b/.gitignore
index a3cd143..94a7cb6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,6 +16,7 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
+*.DS_Store
# CocoaPods
#
diff --git a/SwiftLoader.podspec b/SwiftLoader.podspec
index 0ffd1d0..4ad5a46 100644
--- a/SwiftLoader.podspec
+++ b/SwiftLoader.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SwiftLoader"
- s.version = "0.2.5"
+ s.version = "1.0.0"
s.summary = "A simple and beautiful activity indicator"
s.description = <<-DESC
SwiftLoader is a simple and beautiful activity indicator written in Swift.
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/leoru/SwiftLoader.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/kirill_kunst'
- s.platform = :ios, '8.0'
+ s.platform = :ios, '13.0'
s.requires_arc = true
s.source_files = 'src/SwiftLoader'
diff --git a/example/SwiftLoaderExample/SwiftLoaderExample.xcodeproj/project.pbxproj b/example/SwiftLoaderExample/SwiftLoaderExample.xcodeproj/project.pbxproj
index 5506211..d89c798 100644
--- a/example/SwiftLoaderExample/SwiftLoaderExample.xcodeproj/project.pbxproj
+++ b/example/SwiftLoaderExample/SwiftLoaderExample.xcodeproj/project.pbxproj
@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
- objectVersion = 46;
+ objectVersion = 55;
objects = {
/* Begin PBXBuildFile section */
@@ -109,7 +109,7 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
- LastUpgradeCheck = 0700;
+ LastUpgradeCheck = 1320;
ORGANIZATIONNAME = "Kirill Kunst";
TargetAttributes = {
6A7E7AF61A8B62AB00B7F3B2 = {
@@ -118,8 +118,8 @@
};
};
buildConfigurationList = 6A7E7AF21A8B62AB00B7F3B2 /* Build configuration list for PBXProject "SwiftLoaderExample" */;
- compatibilityVersion = "Xcode 3.2";
- developmentRegion = English;
+ compatibilityVersion = "Xcode 13.0";
+ developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
@@ -176,17 +176,29 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
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_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -195,6 +207,7 @@
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
+ GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
@@ -207,7 +220,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.1;
+ IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -220,17 +233,29 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
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_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -238,15 +263,17 @@
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.1;
+ IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
+ SWIFT_COMPILATION_MODE = wholemodule;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
@@ -257,9 +284,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = SwiftLoaderExample/Info.plist;
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ IPHONEOS_DEPLOYMENT_TARGET = 13.0;
+ LD_RUNPATH_SEARCH_PATHS = (
+ "$(inherited)",
+ "@executable_path/Frameworks",
+ );
PRODUCT_BUNDLE_IDENTIFIER = "com.kunst.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 5.0;
};
name = Debug;
};
@@ -268,9 +300,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = SwiftLoaderExample/Info.plist;
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ IPHONEOS_DEPLOYMENT_TARGET = 13.0;
+ LD_RUNPATH_SEARCH_PATHS = (
+ "$(inherited)",
+ "@executable_path/Frameworks",
+ );
PRODUCT_BUNDLE_IDENTIFIER = "com.kunst.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 5.0;
};
name = Release;
};
diff --git a/example/SwiftLoaderExample/SwiftLoaderExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/SwiftLoaderExample/SwiftLoaderExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
new file mode 100644
index 0000000..18d9810
--- /dev/null
+++ b/example/SwiftLoaderExample/SwiftLoaderExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
@@ -0,0 +1,8 @@
+
+
+
+
+ IDEDidComputeMac32BitWarning
+
+
+
diff --git a/example/SwiftLoaderExample/SwiftLoaderExample/AppDelegate.swift b/example/SwiftLoaderExample/SwiftLoaderExample/AppDelegate.swift
index e3534ca..fda4eb5 100644
--- a/example/SwiftLoaderExample/SwiftLoaderExample/AppDelegate.swift
+++ b/example/SwiftLoaderExample/SwiftLoaderExample/AppDelegate.swift
@@ -12,34 +12,27 @@ import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
-
-
- func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
- self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
+
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
+ self.window = UIWindow(frame: UIScreen.main.bounds)
let vc = ViewController()
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
- self.window?.becomeKeyWindow()
+ self.window?.becomeKey()
return true
}
- func applicationWillResignActive(application: UIApplication) {
- }
-
- func applicationDidEnterBackground(application: UIApplication) {
- }
+ func applicationWillResignActive(_ application: UIApplication) {}
- func applicationWillEnterForeground(application: UIApplication) {
- }
+ func applicationDidEnterBackground(_ application: UIApplication) {}
- func applicationDidBecomeActive(application: UIApplication) {
- }
+ func applicationWillEnterForeground(_ application: UIApplication) {}
- func applicationWillTerminate(application: UIApplication) {
- }
+ func applicationDidBecomeActive(_ application: UIApplication) {}
+ func applicationWillTerminate(_ application: UIApplication) {}
}
diff --git a/example/SwiftLoaderExample/SwiftLoaderExample/Base.lproj/LaunchScreen.xib b/example/SwiftLoaderExample/SwiftLoaderExample/Base.lproj/LaunchScreen.xib
index fb2cfff..29ca8ef 100644
--- a/example/SwiftLoaderExample/SwiftLoaderExample/Base.lproj/LaunchScreen.xib
+++ b/example/SwiftLoaderExample/SwiftLoaderExample/Base.lproj/LaunchScreen.xib
@@ -1,8 +1,10 @@
-
-
+
+
+
-
-
+
+
+
@@ -11,20 +13,20 @@
-
-
+
@@ -38,4 +40,9 @@
+
+
+
+
+
diff --git a/example/SwiftLoaderExample/SwiftLoaderExample/Images.xcassets/AppIcon.appiconset/Contents.json b/example/SwiftLoaderExample/SwiftLoaderExample/Images.xcassets/AppIcon.appiconset/Contents.json
index 36d2c80..9221b9b 100644
--- a/example/SwiftLoaderExample/SwiftLoaderExample/Images.xcassets/AppIcon.appiconset/Contents.json
+++ b/example/SwiftLoaderExample/SwiftLoaderExample/Images.xcassets/AppIcon.appiconset/Contents.json
@@ -2,67 +2,97 @@
"images" : [
{
"idiom" : "iphone",
- "size" : "29x29",
- "scale" : "2x"
+ "scale" : "2x",
+ "size" : "20x20"
},
{
"idiom" : "iphone",
- "size" : "29x29",
- "scale" : "3x"
+ "scale" : "3x",
+ "size" : "20x20"
},
{
"idiom" : "iphone",
- "size" : "40x40",
- "scale" : "2x"
+ "scale" : "2x",
+ "size" : "29x29"
},
{
"idiom" : "iphone",
- "size" : "40x40",
- "scale" : "3x"
+ "scale" : "3x",
+ "size" : "29x29"
},
{
"idiom" : "iphone",
- "size" : "60x60",
- "scale" : "2x"
+ "scale" : "2x",
+ "size" : "40x40"
},
{
"idiom" : "iphone",
- "size" : "60x60",
- "scale" : "3x"
+ "scale" : "3x",
+ "size" : "40x40"
+ },
+ {
+ "idiom" : "iphone",
+ "scale" : "2x",
+ "size" : "60x60"
+ },
+ {
+ "idiom" : "iphone",
+ "scale" : "3x",
+ "size" : "60x60"
+ },
+ {
+ "idiom" : "ipad",
+ "scale" : "1x",
+ "size" : "20x20"
},
{
"idiom" : "ipad",
- "size" : "29x29",
- "scale" : "1x"
+ "scale" : "2x",
+ "size" : "20x20"
},
{
"idiom" : "ipad",
- "size" : "29x29",
- "scale" : "2x"
+ "scale" : "1x",
+ "size" : "29x29"
},
{
"idiom" : "ipad",
- "size" : "40x40",
- "scale" : "1x"
+ "scale" : "2x",
+ "size" : "29x29"
},
{
"idiom" : "ipad",
- "size" : "40x40",
- "scale" : "2x"
+ "scale" : "1x",
+ "size" : "40x40"
},
{
"idiom" : "ipad",
- "size" : "76x76",
- "scale" : "1x"
+ "scale" : "2x",
+ "size" : "40x40"
},
{
"idiom" : "ipad",
- "size" : "76x76",
- "scale" : "2x"
+ "scale" : "1x",
+ "size" : "76x76"
+ },
+ {
+ "idiom" : "ipad",
+ "scale" : "2x",
+ "size" : "76x76"
+ },
+ {
+ "idiom" : "ipad",
+ "scale" : "2x",
+ "size" : "83.5x83.5"
+ },
+ {
+ "idiom" : "ios-marketing",
+ "scale" : "1x",
+ "size" : "1024x1024"
}
],
"info" : {
- "version" : 1,
- "author" : "xcode"
+ "author" : "xcode",
+ "version" : 1
}
-}
\ No newline at end of file
+}
diff --git a/example/SwiftLoaderExample/SwiftLoaderExample/ViewController.swift b/example/SwiftLoaderExample/SwiftLoaderExample/ViewController.swift
index 8ac9655..d6a967d 100644
--- a/example/SwiftLoaderExample/SwiftLoaderExample/ViewController.swift
+++ b/example/SwiftLoaderExample/SwiftLoaderExample/ViewController.swift
@@ -10,42 +10,35 @@ import UIKit
class ViewController: UIViewController {
- func delay(seconds seconds: Double, completion:()->()) {
- let popTime = dispatch_time(DISPATCH_TIME_NOW, Int64( Double(NSEC_PER_SEC) * seconds ))
-
- dispatch_after(popTime, dispatch_get_main_queue()) {
- completion()
- }
+ func delay(seconds: Double, completion: @escaping () -> Void) {
+ DispatchQueue.main.asyncAfter(deadline: .now() + seconds, execute: completion)
}
override func viewDidLoad() {
super.viewDidLoad()
-
self.view.backgroundColor = UIColor(red:0.98, green:0.93, blue:0.81, alpha:1)
self.addButton()
}
func addButton() {
let size : CGFloat = 200.0
- let actionButton = UIButton(frame: CGRectMake((self.view.frame.width - size) / 2, size, size, size))
- actionButton.setTitleColor(UIColor(red:0.52, green:0.07, blue:0.72, alpha:1), forState: UIControlState.Normal)
- actionButton.addTarget(self, action: Selector("actionShowLoader"), forControlEvents: UIControlEvents.TouchUpInside)
- actionButton.setTitle("Show loader", forState: UIControlState.Normal)
+ let actionButton = UIButton(frame: CGRect(x: (self.view.frame.width - size) / 2, y: size, width: size, height: size))
+ actionButton.setTitleColor(UIColor(red:0.52, green:0.07, blue:0.72, alpha:1), for: .normal)
+ actionButton.addTarget(self, action: #selector(actionShowLoader), for: .touchUpInside)
+ actionButton.setTitle("Show loader", for: .normal)
self.view.addSubview(actionButton)
}
- func actionShowLoader() {
-
+ @objc func actionShowLoader() {
var config : SwiftLoader.Config = SwiftLoader.Config()
config.size = 170
config.backgroundColor = UIColor(red:0.03, green:0.82, blue:0.7, alpha:1)
config.spinnerColor = UIColor(red:0.88, green:0.26, blue:0.18, alpha:1)
config.titleTextColor = UIColor(red:0.88, green:0.26, blue:0.18, alpha:1)
config.spinnerLineWidth = 2.0
- config.foregroundColor = UIColor.blackColor()
+ config.foregroundColor = UIColor.black
config.foregroundAlpha = 0.5
-
SwiftLoader.setConfig(config)
SwiftLoader.show(animated: true)
@@ -53,10 +46,10 @@ class ViewController: UIViewController {
delay(seconds: 3.0) { () -> () in
SwiftLoader.show(title: "Loading...", animated: true)
}
+
delay(seconds: 6.0) { () -> () in
SwiftLoader.hide()
}
-
}
diff --git a/src/SwiftLoader/SwiftLoader.swift b/src/SwiftLoader/SwiftLoader.swift
index 02ff629..f9b7727 100644
--- a/src/SwiftLoader/SwiftLoader.swift
+++ b/src/SwiftLoader/SwiftLoader.swift
@@ -1,6 +1,6 @@
//
-// BSLoader.swift
-// Brainstorage
+// SwiftLoader.swift
+// SwiftLoader
//
// Created by Kirill Kunst on 07.02.15.
// Copyright (c) 2015 Kirill Kunst. All rights reserved.
@@ -10,12 +10,14 @@ import UIKit
import QuartzCore
import CoreGraphics
-let loaderSpinnerMarginSide : CGFloat = 35.0
-let loaderSpinnerMarginTop : CGFloat = 20.0
-let loaderTitleMargin : CGFloat = 5.0
-
public class SwiftLoader: UIView {
+ struct Constants {
+ static let loaderSpinnerMarginSide : CGFloat = 35.0
+ static let loaderSpinnerMarginTop : CGFloat = 20.0
+ static let loaderTitleMargin : CGFloat = 5.0
+ }
+
private var coverView : UIView?
private var titleLabel : UILabel?
private var loadingView : SwiftLoadingView?
@@ -30,25 +32,13 @@ public class SwiftLoader: UIView {
}
}
- @objc func rotated(notification: NSNotification) {
-
- let loader = SwiftLoader.sharedInstance
-
- let height : CGFloat = UIScreen.main.bounds.size.height
- let width : CGFloat = UIScreen.main.bounds.size.width
- let center : CGPoint = CGPoint(x: width / 2.0, y: height / 2.0)
-
- loader.center = center
- loader.coverView?.frame = UIScreen.main.bounds
- }
-
override public var frame : CGRect {
didSet {
self.update()
}
}
- class var sharedInstance: SwiftLoader {
+ class var shared: SwiftLoader {
struct Singleton {
static let instance = SwiftLoader(frame: CGRect(origin: CGPoint(x: 0,y: 0),size: CGSize(width: Config().size,height: Config().size)))
}
@@ -60,22 +50,27 @@ public class SwiftLoader: UIView {
}
public class func show(title: String?, animated : Bool) {
+ let currentWindow: UIWindow? = UIApplication
+ .shared
+ .connectedScenes
+ .flatMap { ($0 as? UIWindowScene)?.windows ?? [] }
+ .first { $0.isKeyWindow }
- let currentWindow : UIWindow = UIApplication.shared.keyWindow!
+ guard let currentWindow = currentWindow else { return }
- let loader = SwiftLoader.sharedInstance
+ let loader = SwiftLoader.shared
loader.canUpdated = true
loader.animated = animated
loader.title = title
loader.update()
NotificationCenter.default.addObserver(loader, selector: #selector(loader.rotated(notification: )),
- name: UIDevice.orientationDidChangeNotification,
- object: nil)
+ name: UIDevice.orientationDidChangeNotification,
+ object: nil)
- let height : CGFloat = UIScreen.main.bounds.size.height
- let width : CGFloat = UIScreen.main.bounds.size.width
- let center : CGPoint = CGPoint(x: width / 2.0, y: height / 2.0)
+ let height: CGFloat = UIScreen.main.bounds.size.height
+ let width: CGFloat = UIScreen.main.bounds.size.width
+ let center: CGPoint = CGPoint(x: width / 2.0, y: height / 2.0)
loader.center = center
@@ -90,22 +85,30 @@ public class SwiftLoader: UIView {
}
public class func hide() {
-
- let loader = SwiftLoader.sharedInstance
- NotificationCenter.default.removeObserver(loader)
-
- loader.stop()
+ NotificationCenter.default.removeObserver(SwiftLoader.shared)
+ SwiftLoader.shared.stop()
}
- public class func setConfig(config : Config) {
- let loader = SwiftLoader.sharedInstance
+ public class func setConfig(_ config: Config) {
+ let loader = SwiftLoader.shared
loader.config = config
- loader.frame = CGRect(origin: CGPoint(x: 0, y: 0),size: CGSize(width: loader.config.size, height: loader.config.size))
+ loader.frame = CGRect(origin: CGPoint(x: 0, y: 0),
+ size: CGSize(width: loader.config.size,
+ height: loader.config.size))
}
- /**
- Private methods
- */
+ @objc func rotated(notification: NSNotification) {
+ let loader = SwiftLoader.shared
+
+ let height: CGFloat = UIScreen.main.bounds.size.height
+ let width: CGFloat = UIScreen.main.bounds.size.width
+ let center: CGPoint = CGPoint(x: width / 2.0, y: height / 2.0)
+
+ loader.center = center
+ loader.coverView?.frame = UIScreen.main.bounds
+ }
+
+ // MARK: - Private methods
private func setup() {
self.alpha = 0
@@ -118,8 +121,8 @@ public class SwiftLoader: UIView {
if (self.animated) {
UIView.animate(withDuration: 0.3, animations: { () -> Void in
self.alpha = 1
- }, completion: { (finished) -> Void in
-
+ }, completion: { (finished) -> Void in
+
});
} else {
self.alpha = 1
@@ -127,14 +130,13 @@ public class SwiftLoader: UIView {
}
private func stop() {
-
if (self.animated) {
UIView.animate(withDuration: 0.3, animations: { () -> Void in
self.alpha = 0
- }, completion: { (finished) -> Void in
- self.removeFromSuperview()
- self.coverView?.removeFromSuperview()
- self.loadingView?.stop()
+ }, completion: { (finished) -> Void in
+ self.removeFromSuperview()
+ self.coverView?.removeFromSuperview()
+ self.loadingView?.stop()
});
} else {
self.alpha = 0
@@ -147,40 +149,39 @@ public class SwiftLoader: UIView {
private func update() {
self.backgroundColor = self.config.backgroundColor
self.layer.cornerRadius = self.config.cornerRadius
- let loadingViewSize = self.frame.size.width - (loaderSpinnerMarginSide * 2)
+ let loadingViewSize = self.frame.size.width - (Constants.loaderSpinnerMarginSide * 2)
if (self.loadingView == nil) {
- self.loadingView = SwiftLoadingView(frame: self.frameForSpinner())
+ self.loadingView = SwiftLoadingView(frame: spinnerFrame)
self.addSubview(self.loadingView!)
} else {
- self.loadingView?.frame = self.frameForSpinner()
+ self.loadingView?.frame = spinnerFrame
}
if (self.titleLabel == nil) {
- self.titleLabel = UILabel(frame: CGRect(origin: CGPoint(x: loaderTitleMargin, y: loaderSpinnerMarginTop + loadingViewSize), size: CGSize(width: self.frame.width - loaderTitleMargin*2, height: 42.0)))
+ self.titleLabel = UILabel(frame: CGRect(origin: CGPoint(x: Constants.loaderTitleMargin, y: Constants.loaderSpinnerMarginTop + loadingViewSize), size: CGSize(width: self.frame.width - Constants.loaderTitleMargin*2, height: 42.0)))
self.addSubview(self.titleLabel!)
self.titleLabel?.numberOfLines = 1
self.titleLabel?.textAlignment = NSTextAlignment.center
self.titleLabel?.adjustsFontSizeToFitWidth = true
} else {
- self.titleLabel?.frame = CGRect(origin: CGPoint(x: loaderTitleMargin, y: loaderSpinnerMarginTop + loadingViewSize), size: CGSize(width: self.frame.width - loaderTitleMargin*2, height: 42.0))
+ self.titleLabel?.frame = CGRect(origin: CGPoint(x: Constants.loaderTitleMargin, y: Constants.loaderSpinnerMarginTop + loadingViewSize), size: CGSize(width: self.frame.width - Constants.loaderTitleMargin*2, height: 42.0))
}
self.titleLabel?.font = self.config.titleTextFont
self.titleLabel?.textColor = self.config.titleTextColor
self.titleLabel?.text = self.title
-
self.titleLabel?.isHidden = self.title == nil
}
- func frameForSpinner() -> CGRect {
- let loadingViewSize = self.frame.size.width - (loaderSpinnerMarginSide * 2)
+ var spinnerFrame: CGRect {
+ let loadingViewSize = self.frame.size.width - (Constants.loaderSpinnerMarginSide * 2)
if (self.title == nil) {
let yOffset = (self.frame.size.height - loadingViewSize) / 2
- return CGRect(origin: CGPoint(x: loaderSpinnerMarginSide, y: yOffset), size: CGSize(width: loadingViewSize, height: loadingViewSize))
+ return CGRect(origin: CGPoint(x: Constants.loaderSpinnerMarginSide, y: yOffset), size: CGSize(width: loadingViewSize, height: loadingViewSize))
}
- return CGRect(origin: CGPoint(x: loaderSpinnerMarginSide, y: loaderSpinnerMarginTop), size: CGSize(width: loadingViewSize, height: loadingViewSize))
+ return CGRect(origin: CGPoint(x: Constants.loaderSpinnerMarginSide, y: Constants.loaderSpinnerMarginTop), size: CGSize(width: loadingViewSize, height: loadingViewSize))
}
override init(frame: CGRect) {
@@ -192,9 +193,8 @@ public class SwiftLoader: UIView {
super.init(coder: aDecoder)
}
- /**
- * Loader View
- */
+ // MARK: - Loading View
+
class SwiftLoadingView : UIView {
private var speed : Int?
@@ -218,14 +218,12 @@ public class SwiftLoader: UIView {
super.init(coder: aDecoder)
}
- /**
- Setup loading view
- */
+ //MARK: Setup loading view
func setup() {
self.backgroundColor = UIColor.clear
self.lineWidth = fmaxf(Float(self.frame.size.width) * 0.025, 1)
-
+
self.backgroundLayer = CAShapeLayer()
self.backgroundLayer?.strokeColor = self.config.spinnerColor.cgColor
self.backgroundLayer?.fillColor = self.backgroundColor?.cgColor
@@ -242,15 +240,13 @@ public class SwiftLoader: UIView {
self.backgroundLayer?.strokeColor = self.config.spinnerColor.cgColor
}
- /**
- Draw Circle
- */
+ //MARK: Draw Circle
override func draw(_ rect: CGRect) {
self.backgroundLayer?.frame = self.bounds
}
- func drawBackgroundCircle(partial : Bool) {
+ func drawBackgroundCircle(partial: Bool) {
let startAngle : CGFloat = CGFloat.pi / CGFloat(2.0)
var endAngle : CGFloat = (2.0 * CGFloat.pi) + startAngle
@@ -268,9 +264,7 @@ public class SwiftLoader: UIView {
self.backgroundLayer?.path = processBackgroundPath.cgPath;
}
- /**
- Start and stop spinning
- */
+ // MARK: - Start and stop spinning
func start() {
self.isSpinning? = true
@@ -292,60 +286,38 @@ public class SwiftLoader: UIView {
}
}
+ // MARK: - Loader config
- /**
- * Loader config
- */
public struct Config {
- /**
- * Size of loader
- */
+ /// Size of loader
public var size : CGFloat = 120.0
- /**
- * Color of spinner view
- */
+ /// Color of spinner view
public var spinnerColor = UIColor.black
- /**
- * S
- */
+ /// Line width
public var spinnerLineWidth :Float = 1.0
- /**
- * Color of title text
- */
+ /// Color of title text
public var titleTextColor = UIColor.black
- /**
- * Speed of the spinner
- */
+ /// Speed of the spinner
public var speed :Int = 1
- /**
- * Font for title text in loader
- */
+ /// Font for title text in loader
public var titleTextFont : UIFont = UIFont.boldSystemFont(ofSize: 16.0)
- /**
- * Background color for loader
- */
+ /// Background color for loader
public var backgroundColor = UIColor.white
- /**
- * Foreground color
- */
+ /// Foreground color
public var foregroundColor = UIColor.clear
- /**
- * Foreground alpha CGFloat, between 0.0 and 1.0
- */
+ /// Foreground alpha CGFloat, between 0.0 and 1.0
public var foregroundAlpha:CGFloat = 0.0
- /**
- * Corner radius for loader
- */
+ /// Corner radius for loader
public var cornerRadius : CGFloat = 10.0
public init() {}