Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit e9f95b9

Browse files
author
anho
authored
Merge pull request #41 from nodes-ios/develop
adds potential button image again after spinner is dismissed
2 parents ae94aec + 8dd6958 commit e9f95b9

File tree

6 files changed

+59
-25
lines changed

6 files changed

+59
-25
lines changed

Spinner.xcodeproj/project.pbxproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
isa = PBXProject;
245245
attributes = {
246246
LastSwiftUpdateCheck = 0800;
247-
LastUpgradeCheck = 1010;
247+
LastUpgradeCheck = 1020;
248248
ORGANIZATIONNAME = Nodes;
249249
TargetAttributes = {
250250
275BCA281C57C50A00FF3647 = {
@@ -271,10 +271,11 @@
271271
};
272272
buildConfigurationList = 275BCA231C57C50A00FF3647 /* Build configuration list for PBXProject "Spinner" */;
273273
compatibilityVersion = "Xcode 3.2";
274-
developmentRegion = English;
274+
developmentRegion = en;
275275
hasScannedForEncodings = 0;
276276
knownRegions = (
277277
en,
278+
Base,
278279
);
279280
mainGroup = 275BCA1F1C57C50A00FF3647;
280281
productRefGroup = 275BCA2A1C57C50A00FF3647 /* Products */;
@@ -373,6 +374,7 @@
373374
isa = XCBuildConfiguration;
374375
buildSettings = {
375376
ALWAYS_SEARCH_USER_PATHS = NO;
377+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
376378
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
377379
CLANG_CXX_LIBRARY = "libc++";
378380
CLANG_ENABLE_MODULES = YES;
@@ -431,6 +433,7 @@
431433
isa = XCBuildConfiguration;
432434
buildSettings = {
433435
ALWAYS_SEARCH_USER_PATHS = NO;
436+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
434437
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
435438
CLANG_CXX_LIBRARY = "libc++";
436439
CLANG_ENABLE_MODULES = YES;

Spinner.xcodeproj/xcshareddata/xcschemes/Spinner-tvOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1010"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Spinner.xcodeproj/xcshareddata/xcschemes/Spinner.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1010"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Spinner/Spinner.swift

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class SpinnerView: NSObject, Spinner {
2929

3030
fileprivate var controlTitleColors: [ControlTitleColor]?
3131
fileprivate var controlTitleAttributes: [ControlTitleAttributes]?
32+
fileprivate var buttonImageView: UIImageView?
3233
fileprivate var activityIndicator: UIActivityIndicatorView?
3334
fileprivate var imageView: UIImageView?
3435
fileprivate var userInteractionEnabledAtReception = true
@@ -54,10 +55,13 @@ public class SpinnerView: NSObject, Spinner {
5455

5556
let spinnerView = SpinnerView()
5657
spinnerView.userInteractionEnabledAtReception = view.isUserInteractionEnabled
58+
if let button = view as? UIButton {
59+
spinnerView.buttonImageView = button.imageView
60+
}
5761

5862
//In case the previous spinner wasn't dismissed
5963
if let oldSpinner = view.subviews.filter({ $0 is Spinner }).first as? Spinner {
60-
64+
6165
spinnerView.userInteractionEnabledAtReception = true //We will need to assume userinteraction should be restored as we do not have access to the original SpinnerView
6266
oldSpinner.dismiss()
6367
}
@@ -100,7 +104,6 @@ public class SpinnerView: NSObject, Spinner {
100104
- Returns: A reference to the Spinner that was created, so that it can be dismissed as needed.
101105
*/
102106
public static func showSpinner(inButton button: UIButton, style: UIActivityIndicatorView.Style = .white, color:UIColor? = nil, disablesUserInteraction:Bool = true) -> SpinnerView {
103-
104107
let spinnerView = showSpinner(inView: button, style: style, color: color)
105108
spinnerView.controlTitleColors = button.allTitleColors()
106109
button.removeAllTitleColors()
@@ -124,13 +127,13 @@ public class SpinnerView: NSObject, Spinner {
124127
if let superView = activityIndicator?.superview {
125128
superView.isUserInteractionEnabled = self.userInteractionEnabledAtReception
126129
if let button = superView as? UIButton {
127-
button.restore(titleColors: controlTitleColors, attributedStrings: controlTitleAttributes)
130+
button.restore(titleColors: controlTitleColors, attributedStrings: controlTitleAttributes, buttonImageView: buttonImageView)
128131
}
129132
}
130133
else if let superView = imageView?.superview {
131134
superView.isUserInteractionEnabled = self.userInteractionEnabledAtReception
132135
if let button = superView as? UIButton {
133-
button.restore(titleColors: controlTitleColors, attributedStrings: controlTitleAttributes)
136+
button.restore(titleColors: controlTitleColors, attributedStrings: controlTitleAttributes, buttonImageView: buttonImageView)
134137
}
135138
}
136139

@@ -156,7 +159,7 @@ public extension SpinnerView {
156159
- Parameter images: An array containing the UIImages to use for the animation.
157160
- Parameter duration: The animation duration.
158161
*/
159-
public static func set(customImages images: [UIImage], duration: TimeInterval) {
162+
static func set(customImages images: [UIImage], duration: TimeInterval) {
160163
let image = UIImageView(frame: CGRect(x: 0, y: 0, width: images[0].size.width, height: images[0].size.height))
161164
image.animationImages = images
162165
image.animationDuration = duration
@@ -175,7 +178,7 @@ public extension SpinnerView {
175178

176179
- Returns: A reference to the `Spinner` that was created, so that it can be dismissed as needed.
177180
*/
178-
public static func showCustomSpinner(inView view: UIView, dimBackground: Bool = false) -> SpinnerView {
181+
static func showCustomSpinner(inView view: UIView, dimBackground: Bool = false) -> SpinnerView {
179182
if let image = animationImage {
180183

181184
//In case the previous spinner wasn't dismissed
@@ -217,7 +220,7 @@ public extension SpinnerView {
217220

218221
- Returns: A reference to the ActivityIndicator that was created, so that it can be dismissed as needed
219222
*/
220-
public static func showCustomSpinner(inButton button: UIButton, disablesUserInteraction:Bool = true) -> SpinnerView {
223+
static func showCustomSpinner(inButton button: UIButton, disablesUserInteraction:Bool = true) -> SpinnerView {
221224
let spinnerView = showCustomSpinner(inView: button)
222225
button.isUserInteractionEnabled = !disablesUserInteraction
223226
spinnerView.controlTitleColors = button.allTitleColors()
@@ -255,7 +258,7 @@ extension UIImageView: Spinner {
255258
fileprivate extension UIButton {
256259

257260
// Extension to return an array of every color for every button state
258-
fileprivate func allTitleColors() -> [ControlTitleColor] {
261+
func allTitleColors() -> [ControlTitleColor] {
259262
var colors: [ControlTitleColor] = [
260263
(UIControl.State(), titleColor(for: UIControl.State())),
261264
(.highlighted, titleColor(for: .highlighted)),
@@ -272,7 +275,7 @@ fileprivate extension UIButton {
272275
return colors
273276
}
274277

275-
fileprivate func allTitleAttributes() -> [ControlTitleAttributes] {
278+
func allTitleAttributes() -> [ControlTitleAttributes] {
276279
var attributes: [ControlTitleAttributes] = [
277280
(UIControl.State(), attributedTitle(for: UIControl.State())),
278281
(.highlighted, attributedTitle(for: .highlighted)),
@@ -294,7 +297,7 @@ fileprivate extension UIButton {
294297

295298
- Parameter colors: An array of ControlTitleColor each containing a UIControlState and a UIColor
296299
*/
297-
fileprivate func restore(titleColors colors: [ControlTitleColor]?, attributedStrings: [ControlTitleAttributes]?) {
300+
func restore(titleColors colors: [ControlTitleColor]?, attributedStrings: [ControlTitleAttributes]?, buttonImageView: UIImageView?) {
298301
if colors != nil {
299302
for color in colors! {
300303
if titleColor(for: color.0) == .clear {
@@ -308,19 +311,23 @@ fileprivate extension UIButton {
308311
self.setAttributedTitle(string.1, for: string.0)
309312
}
310313
}
314+
315+
if let buttonImageView = buttonImageView {
316+
addSubview(buttonImageView)
317+
}
311318
}
312319

313320
/**
314321
Sets all the the buttons title colors to clear
315322
*/
316-
fileprivate func removeAllTitleColors() {
323+
func removeAllTitleColors() {
317324
let clearedColors = allTitleColors().map({ return ($0.0, UIColor.clear) })
318325
for color in clearedColors {
319326
setTitleColor(color.1, for: color.0)
320327
}
321328
}
322329

323-
fileprivate func removeAllAttributedStrings() {
330+
func removeAllAttributedStrings() {
324331
self.setAttributedTitle(nil, for: .normal)
325332
self.setAttributedTitle(nil, for: .highlighted)
326333
self.setAttributedTitle(nil, for: .disabled)

0 commit comments

Comments
 (0)