@@ -31,6 +31,10 @@ import NVActivityIndicatorView
3131
3232class ViewController : UIViewController , NVActivityIndicatorViewable {
3333
34+ private let presentingIndicatorTypes = {
35+ return NVActivityIndicatorType . allCases. filter { $0 != . blank }
36+ } ( )
37+
3438 override func viewDidLoad( ) {
3539 super. viewDidLoad ( )
3640
@@ -41,30 +45,30 @@ class ViewController: UIViewController, NVActivityIndicatorViewable {
4145 let cellWidth = Int ( self . view. frame. width / CGFloat( cols) )
4246 let cellHeight = Int ( self . view. frame. height / CGFloat( rows) )
4347
44- ( NVActivityIndicatorType . ballPulse . rawValue ... NVActivityIndicatorType . circleStrokeSpin . rawValue ) . forEach {
45- let x = ( $0 - 1 ) % cols * cellWidth
46- let y = ( $0 - 1 ) / cols * cellHeight
48+ for (index , indicatorType ) in presentingIndicatorTypes . enumerated ( ) {
49+ let x = index % cols * cellWidth
50+ let y = index / cols * cellHeight
4751 let frame = CGRect ( x: x, y: y, width: cellWidth, height: cellHeight)
4852 let activityIndicatorView = NVActivityIndicatorView ( frame: frame,
49- type: NVActivityIndicatorType ( rawValue : $0 ) ! )
53+ type: indicatorType )
5054 let animationTypeLabel = UILabel ( frame: frame)
5155
52- animationTypeLabel. text = String ( $0 )
56+ animationTypeLabel. text = String ( index )
5357 animationTypeLabel. sizeToFit ( )
5458 animationTypeLabel. textColor = UIColor . white
5559 animationTypeLabel. frame. origin. x += 5
5660 animationTypeLabel. frame. origin. y += CGFloat ( cellHeight) - animationTypeLabel. frame. size. height
5761
5862 activityIndicatorView. padding = 20
59- if $0 == NVActivityIndicatorType . orbit. rawValue {
63+ if indicatorType == NVActivityIndicatorType . orbit {
6064 activityIndicatorView. padding = 0
6165 }
6266 self . view. addSubview ( activityIndicatorView)
6367 self . view. addSubview ( animationTypeLabel)
6468 activityIndicatorView. startAnimating ( )
6569
6670 let button : UIButton = UIButton ( frame: frame)
67- button. tag = $0
71+ button. tag = index
6872 #if swift(>=4.2)
6973 button. addTarget ( self ,
7074 action: #selector( buttonTapped ( _: ) ) ,
@@ -80,8 +84,10 @@ class ViewController: UIViewController, NVActivityIndicatorViewable {
8084
8185 @objc func buttonTapped( _ sender: UIButton ) {
8286 let size = CGSize ( width: 30 , height: 30 )
87+ let selectedIndicatorIndex = sender. tag
88+ let indicatorType = presentingIndicatorTypes [ selectedIndicatorIndex]
8389
84- startAnimating ( size, message: " Loading... " , type: NVActivityIndicatorType ( rawValue : sender . tag ) ! , fadeInAnimation: nil )
90+ startAnimating ( size, message: " Loading... " , type: indicatorType , fadeInAnimation: nil )
8591
8692 DispatchQueue . main. asyncAfter ( deadline: DispatchTime . now ( ) + 1.5 ) {
8793 NVActivityIndicatorPresenter . sharedInstance. setMessage ( " Authenticating... " )
0 commit comments