Skip to content

Commit 71f7a2b

Browse files
committed
Format all Swift files in project
1 parent 3a9516a commit 71f7a2b

File tree

109 files changed

+11378
-11087
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+11378
-11087
lines changed

Carthage/Checkouts/MarqueeLabel/Extras/NoReturnAnimation.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
import UIKit
99

1010
open class NoAnimationReturn: MarqueeLabel {
11-
// Override labelWillBeginScroll to catch when a scroll animation starts
12-
override open func labelWillBeginScroll() {
13-
// This only makes sense for leftRight and rightLeft types
14-
if type == .leftRight || type == .rightLeft {
15-
// Calculate "away" position time after scroll start
16-
let awayTime = animationDelay + animationDuration
17-
// Schedule a timer to restart the label when it hits the "away" position
18-
Timer.scheduledTimer(timeInterval: TimeInterval(awayTime), target: self, selector: #selector(restartLabel), userInfo: nil, repeats: false)
19-
}
11+
// Override labelWillBeginScroll to catch when a scroll animation starts
12+
override open func labelWillBeginScroll() {
13+
// This only makes sense for leftRight and rightLeft types
14+
if type == .leftRight || type == .rightLeft {
15+
// Calculate "away" position time after scroll start
16+
let awayTime = animationDelay + animationDuration
17+
// Schedule a timer to restart the label when it hits the "away" position
18+
Timer.scheduledTimer(
19+
timeInterval: TimeInterval(awayTime), target: self, selector: #selector(restartLabel), userInfo: nil,
20+
repeats: false)
2021
}
22+
}
2123
}

Carthage/Checkouts/MarqueeLabel/Extras/SingleShotOffscreenLabel.swift

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,32 @@
99
import UIKit
1010

1111
open class SingleShotOffscreenLabel: MarqueeLabel {
12-
// Override layoutSubviews to catch frame size changes
13-
open override func layoutSubviews() {
14-
// Set trailingBuffer to frame width + 10 (to be sure)
15-
trailingBuffer = frame.width
16-
super.layoutSubviews()
17-
}
18-
19-
// Override labelWillBeginScroll to catch when a scroll animation starts
20-
open override func labelWillBeginScroll() {
21-
// This only makes sense for leftRight and rightLeft types
22-
if type == .leftRight || type == .rightLeft {
23-
// Calculate "away" position time after scroll start
24-
let awayTime = animationDelay + animationDuration
25-
// Schedule a timer to restart the label when it hits the "away" position
26-
Timer.scheduledTimer(timeInterval: TimeInterval(awayTime), target: self, selector: #selector(pauseAndClear), userInfo: nil, repeats: false)
27-
}
28-
}
29-
30-
@objc public func pauseAndClear() {
31-
// Pause label offscreen
32-
pauseLabel()
33-
// Change text to nil
34-
text = nil
35-
// Unpause (empty) label, clearing the way for a subsequent text change to trigger scroll
36-
unpauseLabel()
12+
// Override layoutSubviews to catch frame size changes
13+
open override func layoutSubviews() {
14+
// Set trailingBuffer to frame width + 10 (to be sure)
15+
trailingBuffer = frame.width
16+
super.layoutSubviews()
17+
}
18+
19+
// Override labelWillBeginScroll to catch when a scroll animation starts
20+
open override func labelWillBeginScroll() {
21+
// This only makes sense for leftRight and rightLeft types
22+
if type == .leftRight || type == .rightLeft {
23+
// Calculate "away" position time after scroll start
24+
let awayTime = animationDelay + animationDuration
25+
// Schedule a timer to restart the label when it hits the "away" position
26+
Timer.scheduledTimer(
27+
timeInterval: TimeInterval(awayTime), target: self, selector: #selector(pauseAndClear), userInfo: nil,
28+
repeats: false)
3729
}
30+
}
31+
32+
@objc public func pauseAndClear() {
33+
// Pause label offscreen
34+
pauseLabel()
35+
// Change text to nil
36+
text = nil
37+
// Unpause (empty) label, clearing the way for a subsequent text change to trigger scroll
38+
unpauseLabel()
39+
}
3840
}

Carthage/Checkouts/MarqueeLabel/MarqueeLabel/AppDelegate.swift

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,36 @@ import UIKit
1111
@UIApplicationMain
1212
class AppDelegate: UIResponder, UIApplicationDelegate {
1313

14-
var window: UIWindow?
15-
16-
17-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
18-
// Override point for customization after application launch.
19-
return true
20-
}
21-
22-
func applicationWillResignActive(_ application: UIApplication) {
23-
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24-
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25-
}
26-
27-
func applicationDidEnterBackground(_ application: UIApplication) {
28-
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30-
}
31-
32-
func applicationWillEnterForeground(_ application: UIApplication) {
33-
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34-
}
35-
36-
func applicationDidBecomeActive(_ application: UIApplication) {
37-
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38-
}
39-
40-
func applicationWillTerminate(_ application: UIApplication) {
41-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42-
}
43-
14+
var window: UIWindow?
15+
16+
func application(
17+
_ application: UIApplication,
18+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
19+
) -> Bool {
20+
// Override point for customization after application launch.
21+
return true
22+
}
23+
24+
func applicationWillResignActive(_ application: UIApplication) {
25+
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
26+
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
27+
}
28+
29+
func applicationDidEnterBackground(_ application: UIApplication) {
30+
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
31+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
32+
}
33+
34+
func applicationWillEnterForeground(_ application: UIApplication) {
35+
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
36+
}
37+
38+
func applicationDidBecomeActive(_ application: UIApplication) {
39+
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
40+
}
41+
42+
func applicationWillTerminate(_ application: UIApplication) {
43+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
44+
}
4445

4546
}
46-

Carthage/Checkouts/MarqueeLabel/MarqueeLabel/MarqueeLabelDemoPushController.swift

Lines changed: 91 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -9,89 +9,96 @@
99
import UIKit
1010

1111
class MarqueeLabelDemoPushController: UIViewController {
12-
@IBOutlet weak var demoLabel: MarqueeLabel!
13-
@IBOutlet weak var labelLabel: UILabel!
14-
15-
override func viewDidLoad() {
16-
super.viewDidLoad()
17-
18-
demoLabel.type = MarqueeLabel.MarqueeType.allCases.randomElement() ?? .continuous
19-
// Set label label text
20-
labelLabel.text = { () -> String in
21-
switch demoLabel.type {
22-
case .continuous:
23-
return "Continuous scrolling"
24-
case .continuousReverse:
25-
return "Continuous Reverse scrolling"
26-
case .left:
27-
return "Left-Only scrolling"
28-
case .leftRight:
29-
return "Left-Right scrolling"
30-
case .right:
31-
return "Right-Only scrolling"
32-
case .rightLeft:
33-
return "Right-Left scrolling"
34-
}
35-
}()
36-
37-
demoLabel.speed = .duration(15)
38-
demoLabel.animationCurve = .easeInOut
39-
demoLabel.fadeLength = 10.0
40-
demoLabel.leadingBuffer = 30.0
41-
42-
let strings = ["When shall we three meet again in thunder, lightning, or in rain? When the hurlyburly's done, When the battle 's lost and won.",
43-
"I have no spur to prick the sides of my intent, but only vaulting ambition, which o'erleaps itself, and falls on the other.",
44-
"Double, double toil and trouble; Fire burn, and cauldron bubble.",
45-
"By the pricking of my thumbs, Something wicked this way comes.",
46-
"My favorite things in life don't cost any money. It's really clear that the most precious resource we all have is time.",
47-
"Be a yardstick of quality. Some people aren't used to an environment where excellence is expected."]
48-
49-
demoLabel.text = strings[Int(arc4random_uniform(UInt32(strings.count)))]
50-
51-
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.didTap(_:)))
52-
tapRecognizer.numberOfTapsRequired = 1
53-
tapRecognizer.numberOfTouchesRequired = 1
54-
demoLabel.addGestureRecognizer(tapRecognizer)
55-
demoLabel.isUserInteractionEnabled = true
56-
}
57-
58-
@objc func didTap(_ recognizer: UIGestureRecognizer) {
59-
let label = recognizer.view as! MarqueeLabel
60-
if recognizer.state == .ended {
61-
label.isPaused ? label.unpauseLabel() : label.pauseLabel()
62-
// Convert tap points
63-
let tapPoint = recognizer.location(in: label)
64-
print("Frame coord: \(tapPoint)")
65-
guard let textPoint = label.textCoordinateForFramePoint(tapPoint) else {
66-
return
67-
}
68-
print(" Text coord: \(textPoint)")
69-
70-
// Thanks to Toomas Vahter for the basis of the below
71-
// https://augmentedcode.io/2020/12/20/opening-hyperlinks-in-uilabel-on-ios/
72-
// Create layout manager
73-
let layoutManager = NSLayoutManager()
74-
let textContainer = NSTextContainer(size: label.textLayoutSize())
75-
textContainer.lineFragmentPadding = 0
76-
// Create text storage
77-
guard let text = label.text else { return }
78-
let textStorage = NSTextStorage(string: "")
79-
textStorage.setAttributedString(label.attributedText!)
80-
layoutManager.addTextContainer(textContainer)
81-
textStorage.addLayoutManager(layoutManager)
82-
textContainer.lineBreakMode = label.lineBreakMode
83-
textContainer.size = label.textRect(forBounds: CGRect(origin: .zero, size:label.textLayoutSize()), limitedToNumberOfLines: label.numberOfLines).size
84-
85-
let characterIndex = layoutManager.characterIndex(for: textPoint, in: textContainer, fractionOfDistanceBetweenInsertionPoints: nil)
86-
guard characterIndex >= 0, characterIndex != NSNotFound else {
87-
print("No character at point found!")
88-
return
89-
}
90-
91-
let stringIndex = text.index(text.startIndex, offsetBy: characterIndex)
92-
// Print character under touch point
93-
print("Character under touch point: \(text[stringIndex])")
94-
}
12+
@IBOutlet weak var demoLabel: MarqueeLabel!
13+
@IBOutlet weak var labelLabel: UILabel!
14+
15+
override func viewDidLoad() {
16+
super.viewDidLoad()
17+
18+
demoLabel.type = MarqueeLabel.MarqueeType.allCases.randomElement() ?? .continuous
19+
// Set label label text
20+
labelLabel.text = { () -> String in
21+
switch demoLabel.type {
22+
case .continuous:
23+
return "Continuous scrolling"
24+
case .continuousReverse:
25+
return "Continuous Reverse scrolling"
26+
case .left:
27+
return "Left-Only scrolling"
28+
case .leftRight:
29+
return "Left-Right scrolling"
30+
case .right:
31+
return "Right-Only scrolling"
32+
case .rightLeft:
33+
return "Right-Left scrolling"
34+
}
35+
}()
36+
37+
demoLabel.speed = .duration(15)
38+
demoLabel.animationCurve = .easeInOut
39+
demoLabel.fadeLength = 10.0
40+
demoLabel.leadingBuffer = 30.0
41+
42+
let strings = [
43+
"When shall we three meet again in thunder, lightning, or in rain? When the hurlyburly's done, When the battle 's lost and won.",
44+
"I have no spur to prick the sides of my intent, but only vaulting ambition, which o'erleaps itself, and falls on the other.",
45+
"Double, double toil and trouble; Fire burn, and cauldron bubble.",
46+
"By the pricking of my thumbs, Something wicked this way comes.",
47+
"My favorite things in life don't cost any money. It's really clear that the most precious resource we all have is time.",
48+
"Be a yardstick of quality. Some people aren't used to an environment where excellence is expected.",
49+
]
50+
51+
demoLabel.text = strings[Int(arc4random_uniform(UInt32(strings.count)))]
52+
53+
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.didTap(_:)))
54+
tapRecognizer.numberOfTapsRequired = 1
55+
tapRecognizer.numberOfTouchesRequired = 1
56+
demoLabel.addGestureRecognizer(tapRecognizer)
57+
demoLabel.isUserInteractionEnabled = true
58+
}
59+
60+
@objc func didTap(_ recognizer: UIGestureRecognizer) {
61+
let label = recognizer.view as! MarqueeLabel
62+
if recognizer.state == .ended {
63+
label.isPaused ? label.unpauseLabel() : label.pauseLabel()
64+
// Convert tap points
65+
let tapPoint = recognizer.location(in: label)
66+
print("Frame coord: \(tapPoint)")
67+
guard let textPoint = label.textCoordinateForFramePoint(tapPoint) else {
68+
return
69+
}
70+
print(" Text coord: \(textPoint)")
71+
72+
// Thanks to Toomas Vahter for the basis of the below
73+
// https://augmentedcode.io/2020/12/20/opening-hyperlinks-in-uilabel-on-ios/
74+
// Create layout manager
75+
let layoutManager = NSLayoutManager()
76+
let textContainer = NSTextContainer(size: label.textLayoutSize())
77+
textContainer.lineFragmentPadding = 0
78+
// Create text storage
79+
guard let text = label.text else { return }
80+
let textStorage = NSTextStorage(string: "")
81+
textStorage.setAttributedString(label.attributedText!)
82+
layoutManager.addTextContainer(textContainer)
83+
textStorage.addLayoutManager(layoutManager)
84+
textContainer.lineBreakMode = label.lineBreakMode
85+
textContainer.size =
86+
label.textRect(
87+
forBounds: CGRect(origin: .zero, size: label.textLayoutSize()),
88+
limitedToNumberOfLines: label.numberOfLines
89+
).size
90+
91+
let characterIndex = layoutManager.characterIndex(
92+
for: textPoint, in: textContainer, fractionOfDistanceBetweenInsertionPoints: nil)
93+
guard characterIndex >= 0, characterIndex != NSNotFound else {
94+
print("No character at point found!")
95+
return
96+
}
97+
98+
let stringIndex = text.index(text.startIndex, offsetBy: characterIndex)
99+
// Print character under touch point
100+
print("Character under touch point: \(text[stringIndex])")
95101
}
96-
102+
}
103+
97104
}

0 commit comments

Comments
 (0)