@@ -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 {
255258fileprivate 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