@@ -30,22 +30,22 @@ public class MarqueeLabel: UILabel {
30
30
//
31
31
32
32
/**
33
- Defines the direction and method in which the `MarqueeLabel` instance scrolls.
34
- `MarqueeLabel` supports four types of scrolling: `MLLeftRight`, `MLRightLeft`, `MLContinuous`, and `MLContinuousReverse`.
35
-
36
- Given the nature of how text direction works, the options for the `marqueeType` property require specific text alignments
37
- and will set the textAlignment property accordingly.
38
-
39
- - `MLLeftRight` type is ONLY compatible with a label text alignment of `NSTextAlignmentLeft`.
40
- - `MLRightLeft` type is ONLY compatible with a label text alignment of `NSTextAlignmentRight`.
41
- - `MLContinuous` does not require a text alignment (it is effectively centered).
42
- - `MLContinuousReverse` does not require a text alignment (it is effectively centered).
43
-
44
- Defaults to `MLContinuous`.
45
-
46
- - SeeAlso: Type
47
- - SeeAlso: textAlignment
48
- */
33
+ Defines the direction and method in which the `MarqueeLabel` instance scrolls.
34
+ `MarqueeLabel` supports four types of scrolling: `MLLeftRight`, `MLRightLeft`, `MLContinuous`, and `MLContinuousReverse`.
35
+
36
+ Given the nature of how text direction works, the options for the `marqueeType` property require specific text alignments
37
+ and will set the textAlignment property accordingly.
38
+
39
+ - `MLLeftRight` type is ONLY compatible with a label text alignment of `NSTextAlignmentLeft`.
40
+ - `MLRightLeft` type is ONLY compatible with a label text alignment of `NSTextAlignmentRight`.
41
+ - `MLContinuous` does not require a text alignment (it is effectively centered).
42
+ - `MLContinuousReverse` does not require a text alignment (it is effectively centered).
43
+
44
+ Defaults to `MLContinuous`.
45
+
46
+ - SeeAlso: Type
47
+ - SeeAlso: textAlignment
48
+ */
49
49
public var type : Type = . Continuous {
50
50
didSet {
51
51
if type == oldValue {
@@ -132,7 +132,7 @@ public class MarqueeLabel: UILabel {
132
132
didSet {
133
133
if tapToScroll != oldValue {
134
134
if tapToScroll {
135
- let tapRecognizer = UITapGestureRecognizer ( target: self , action: " labelWasTapped: " )
135
+ let tapRecognizer = UITapGestureRecognizer ( target: self , action: #selector ( MarqueeLabel . labelWasTapped ( _ : ) ) )
136
136
self . addGestureRecognizer ( tapRecognizer)
137
137
userInteractionEnabled = true
138
138
} else {
@@ -317,20 +317,20 @@ public class MarqueeLabel: UILabel {
317
317
//
318
318
319
319
/**
320
- Convenience method to restart all `MarqueeLabel` instances that have the specified view controller in their next responder chain.
321
-
322
- - Parameter controller: The view controller for which to restart all `MarqueeLabel` instances.
323
-
324
- - Warning: View controllers that appear with animation (such as from underneath a modal-style controller) can cause some `MarqueeLabel` text
325
- position "jumping" when this method is used in `viewDidAppear` if scroll animations are already underway. Use this method inside `viewWillAppear:`
326
- instead to avoid this problem.
327
-
328
- - Warning: This method may not function properly if passed the parent view controller when using view controller containment.
329
-
330
- - SeeAlso: restartLabel
331
- - SeeAlso: controllerViewDidAppear:
332
- - SeeAlso: controllerViewWillAppear:
333
- */
320
+ Convenience method to restart all `MarqueeLabel` instances that have the specified view controller in their next responder chain.
321
+
322
+ - Parameter controller: The view controller for which to restart all `MarqueeLabel` instances.
323
+
324
+ - Warning: View controllers that appear with animation (such as from underneath a modal-style controller) can cause some `MarqueeLabel` text
325
+ position "jumping" when this method is used in `viewDidAppear` if scroll animations are already underway. Use this method inside `viewWillAppear:`
326
+ instead to avoid this problem.
327
+
328
+ - Warning: This method may not function properly if passed the parent view controller when using view controller containment.
329
+
330
+ - SeeAlso: restartLabel
331
+ - SeeAlso: controllerViewDidAppear:
332
+ - SeeAlso: controllerViewWillAppear:
333
+ */
334
334
class func restartLabelsOfController( controller: UIViewController ) {
335
335
MarqueeLabel . notifyController ( controller, message: . Restart)
336
336
}
@@ -391,14 +391,14 @@ public class MarqueeLabel: UILabel {
391
391
//
392
392
393
393
/**
394
- Returns a newly initialized `MarqueeLabel` instance with the specified scroll rate and edge transparency fade length.
395
-
396
- - Parameter frame: A rectangle specifying the initial location and size of the view in its superview's coordinates. Text (for the given font, font size, etc.) that does not fit in this frame will automatically scroll.
397
- - Parameter pixelsPerSec: A rate of scroll for the label scroll animation. Must be non-zero. Note that this will be the peak (mid-transition) rate for ease-type animation.
398
- - Parameter fadeLength: A length of transparency fade at the left and right edges of the `MarqueeLabel` instance's frame.
399
- - Returns: An initialized `MarqueeLabel` object or nil if the object couldn't be created.
400
- - SeeAlso: fadeLength
401
- */
394
+ Returns a newly initialized `MarqueeLabel` instance with the specified scroll rate and edge transparency fade length.
395
+
396
+ - Parameter frame: A rectangle specifying the initial location and size of the view in its superview's coordinates. Text (for the given font, font size, etc.) that does not fit in this frame will automatically scroll.
397
+ - Parameter pixelsPerSec: A rate of scroll for the label scroll animation. Must be non-zero. Note that this will be the peak (mid-transition) rate for ease-type animation.
398
+ - Parameter fadeLength: A length of transparency fade at the left and right edges of the `MarqueeLabel` instance's frame.
399
+ - Returns: An initialized `MarqueeLabel` object or nil if the object couldn't be created.
400
+ - SeeAlso: fadeLength
401
+ */
402
402
init ( frame: CGRect , rate: CGFloat , fadeLength fade: CGFloat ) {
403
403
speed = . Rate( rate)
404
404
fadeLength = CGFloat ( min ( fade, frame. size. width/ 2.0 ) )
@@ -455,12 +455,12 @@ public class MarqueeLabel: UILabel {
455
455
456
456
// Add notification observers
457
457
// Custom class notifications
458
- NSNotificationCenter . defaultCenter ( ) . addObserver ( self , selector: " restartForViewController: " , name: MarqueeKeys . Restart. rawValue, object: nil )
459
- NSNotificationCenter . defaultCenter ( ) . addObserver ( self , selector: " labelizeForController: " , name: MarqueeKeys . Labelize. rawValue, object: nil )
460
- NSNotificationCenter . defaultCenter ( ) . addObserver ( self , selector: " animateForController: " , name: MarqueeKeys . Animate. rawValue, object: nil )
458
+ NSNotificationCenter . defaultCenter ( ) . addObserver ( self , selector: #selector ( restartForViewController ( _ : ) ) , name: MarqueeKeys . Restart. rawValue, object: nil )
459
+ NSNotificationCenter . defaultCenter ( ) . addObserver ( self , selector: #selector ( labelizeForController ( _ : ) ) , name: MarqueeKeys . Labelize. rawValue, object: nil )
460
+ NSNotificationCenter . defaultCenter ( ) . addObserver ( self , selector: #selector ( animateForController ( _ : ) ) , name: MarqueeKeys . Animate. rawValue, object: nil )
461
461
// UIApplication state notifications
462
- NSNotificationCenter . defaultCenter ( ) . addObserver ( self , selector: " restartLabel " , name: UIApplicationDidBecomeActiveNotification, object: nil )
463
- NSNotificationCenter . defaultCenter ( ) . addObserver ( self , selector: " shutdownLabel " , name: UIApplicationDidEnterBackgroundNotification, object: nil )
462
+ NSNotificationCenter . defaultCenter ( ) . addObserver ( self , selector: #selector ( restartLabel) , name: UIApplicationDidBecomeActiveNotification, object: nil )
463
+ NSNotificationCenter . defaultCenter ( ) . addObserver ( self , selector: #selector ( shutdownLabel) , name: UIApplicationDidEnterBackgroundNotification, object: nil )
464
464
}
465
465
466
466
override public func awakeFromNib( ) {
@@ -470,17 +470,17 @@ public class MarqueeLabel: UILabel {
470
470
471
471
private func forwardPropertiesToSublabel( ) {
472
472
/*
473
- Note that this method is currently ONLY called from awakeFromNib, i.e. when
474
- text properties are set via a Storyboard. As the Storyboard/IB doesn't currently
475
- support attributed strings, there's no need to "forward" the super attributedString value.
476
- */
473
+ Note that this method is currently ONLY called from awakeFromNib, i.e. when
474
+ text properties are set via a Storyboard. As the Storyboard/IB doesn't currently
475
+ support attributed strings, there's no need to "forward" the super attributedString value.
476
+ */
477
477
478
478
// Since we're a UILabel, we actually do implement all of UILabel's properties.
479
479
// We don't care about these values, we just want to forward them on to our sublabel.
480
480
let properties = [ " baselineAdjustment " , " enabled " , " highlighted " , " highlightedTextColor " ,
481
- " minimumFontSize " , " shadowOffset " , " textAlignment " ,
482
- " userInteractionEnabled " , " adjustsFontSizeToFitWidth " ,
483
- " lineBreakMode " , " numberOfLines " ]
481
+ " minimumFontSize " , " shadowOffset " , " textAlignment " ,
482
+ " userInteractionEnabled " , " adjustsFontSizeToFitWidth " ,
483
+ " lineBreakMode " , " numberOfLines " ]
484
484
485
485
// Iterate through properties
486
486
sublabel. text = super. text
@@ -725,7 +725,8 @@ public class MarqueeLabel: UILabel {
725
725
// Define animation completion closure type
726
726
private typealias MLAnimationCompletion = ( finished: Bool ) -> ( )
727
727
728
- private func scroll( interval: CGFloat , delay: CGFloat = 0.0 , var scroller: Scroller , fader: CAKeyframeAnimation ? ) {
728
+ private func scroll( interval: CGFloat , delay: CGFloat = 0.0 , scroller_: Scroller , fader: CAKeyframeAnimation ? ) {
729
+ var scroller : Scroller = scroller_
729
730
// Check for conditions which would prevent scrolling
730
731
if !labelReadyForScroll( ) {
731
732
return
@@ -780,7 +781,7 @@ public class MarqueeLabel: UILabel {
780
781
// Begin again, if conditions met
781
782
if ( self . labelShouldScroll ( ) && !self . tapToScroll && !self . holdScrolling) {
782
783
// Perform completion callback
783
- self . scroll ( interval, delay: delay, scroller : scroller, fader: gradientAnimation)
784
+ self . scroll ( interval, delay: delay, scroller_ : scroller, fader: gradientAnimation)
784
785
}
785
786
}
786
787
} )
@@ -827,7 +828,7 @@ public class MarqueeLabel: UILabel {
827
828
} )
828
829
829
830
// Scroll
830
- scroll ( interval, delay: delay, scroller : scroller, fader: nil )
831
+ scroll ( interval, delay: delay, scroller_ : scroller, fader: nil )
831
832
}
832
833
833
834
@@ -852,7 +853,7 @@ public class MarqueeLabel: UILabel {
852
853
} )
853
854
854
855
// Scroll
855
- scroll ( interval, delay: delay, scroller : scroller, fader: nil )
856
+ scroll ( interval, delay: delay, scroller_ : scroller, fader: nil )
856
857
}
857
858
858
859
private func applyGradientMask( fadeLength: CGFloat, animated: Bool) {
@@ -905,7 +906,7 @@ public class MarqueeLabel: UILabel {
905
906
case . ContinuousReverse, . RightLeft:
906
907
adjustedColors = [ ( trailingFadeNeeded ? transparent : opaque) , opaque, opaque, opaque]
907
908
908
- // .MLContinuous, .MLLeftRight
909
+ // .MLContinuous, .MLLeftRight
909
910
default :
910
911
adjustedColors = [ opaque, opaque, opaque, ( trailingFadeNeeded ? transparent : opaque) ]
911
912
break
@@ -964,7 +965,7 @@ public class MarqueeLabel: UILabel {
964
965
1.0 // 9) End of LE fade out, just as scroll home finishes
965
966
]
966
967
967
- // .MLContinuous, .MLContinuousReverse
968
+ // .MLContinuous, .MLContinuousReverse
968
969
default :
969
970
// Calculate total animation duration
970
971
let totalDuration = delay + interval
@@ -1081,7 +1082,7 @@ public class MarqueeLabel: UILabel {
1081
1082
]
1082
1083
1083
1084
// .Continuous
1084
- // .ContinuousReverse
1085
+ // .ContinuousReverse
1085
1086
default :
1086
1087
//NSAssert(values.count == 3, @"Incorrect number of values passed for MLContinous-type animation")
1087
1088
totalDuration = delay + interval
@@ -1212,19 +1213,19 @@ public class MarqueeLabel: UILabel {
1212
1213
//
1213
1214
1214
1215
/**
1215
- Overrides any non-size condition which is preventing the receiver from automatically scrolling, and begins a scroll animation.
1216
-
1217
- Currently the only non-size conditions which can prevent a label from scrolling are the `tapToScroll` and `holdScrolling` properties. This
1218
- method will not force a label with a string that fits inside the label bounds (i.e. that would not automatically scroll) to begin a scroll
1219
- animation.
1220
-
1221
- Upon the completion of the first forced scroll animation, the receiver will not automatically continue to scroll unless the conditions
1222
- preventing scrolling have been removed.
1223
-
1224
- - Note: This method has no effect if called during an already in-flight scroll animation.
1225
-
1226
- - SeeAlso: restartLabel
1227
- */
1216
+ Overrides any non-size condition which is preventing the receiver from automatically scrolling, and begins a scroll animation.
1217
+
1218
+ Currently the only non-size conditions which can prevent a label from scrolling are the `tapToScroll` and `holdScrolling` properties. This
1219
+ method will not force a label with a string that fits inside the label bounds (i.e. that would not automatically scroll) to begin a scroll
1220
+ animation.
1221
+
1222
+ Upon the completion of the first forced scroll animation, the receiver will not automatically continue to scroll unless the conditions
1223
+ preventing scrolling have been removed.
1224
+
1225
+ - Note: This method has no effect if called during an already in-flight scroll animation.
1226
+
1227
+ - SeeAlso: restartLabel
1228
+ */
1228
1229
public func triggerScrollStart( ) {
1229
1230
if labelShouldScroll ( ) && !awayFromHome {
1230
1231
beginScroll ( )
@@ -1368,8 +1369,8 @@ public class MarqueeLabel: UILabel {
1368
1369
1369
1370
#if os(iOS)
1370
1371
override public func viewForBaselineLayout( ) - > UIView {
1371
- // Use subLabel view for handling baseline layouts
1372
- return sublabel
1372
+ // Use subLabel view for handling baseline layouts
1373
+ return sublabel
1373
1374
}
1374
1375
#endif
1375
1376
@@ -1651,7 +1652,7 @@ private extension CAMediaTimingFunction {
1651
1652
var t1 = y_0
1652
1653
var f0 , df0 : CGFloat
1653
1654
1654
- for ( var i = 0 ; i < 15 ; i ++ ) {
1655
+ for _ in 0 .. < 15 {
1655
1656
// Base this iteration of t1 calculated from last iteration
1656
1657
t0 = t1
1657
1658
// Calculate f(t0)
@@ -1724,7 +1725,7 @@ private extension CAMediaTimingFunction {
1724
1725
// Create point array to point to
1725
1726
var point : [ Float ] = [ 0.0 , 0.0 ]
1726
1727
var pointArray = [ CGPoint] ( )
1727
- for ( var i : Int = 0 ; i <= 3 ; i ++ ) {
1728
+ for i in 0 ..< 4 {
1728
1729
self . getControlPointAtIndex ( i, values: & point)
1729
1730
pointArray. append ( CGPoint ( x: CGFloat ( point [ 0 ] ) , y: CGFloat ( point [ 1 ] ) ) )
1730
1731
}
0 commit comments