Skip to content

Commit 9198a10

Browse files
committed
13.7.1
1 parent b340c56 commit 9198a10

File tree

3 files changed

+77
-64
lines changed

3 files changed

+77
-64
lines changed

ProgressHUD/Sources/ProgressHUD.swift

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ extension AlertIcon {
9595
//-----------------------------------------------------------------------------------------------------------------------------------------------
9696
public extension ProgressHUD {
9797

98+
class var mediaSize: CGFloat {
99+
get { shared.mediaSize }
100+
set { shared.mediaSize = newValue }
101+
}
102+
103+
class var marginSize: CGFloat {
104+
get { shared.marginSize }
105+
set { shared.marginSize = newValue }
106+
}
107+
98108
class var animationType: AnimationType {
99109
get { shared.animationType }
100110
set { shared.animationType = newValue }
@@ -253,13 +263,16 @@ public class ProgressHUD: UIView {
253263

254264
private var timer: Timer?
255265

266+
private var mediaSize: CGFloat = 70
267+
private var marginSize: CGFloat = 30
268+
256269
private var viewBackground: UIView?
257270
private var toolbarHUD: UIToolbar?
258271
private var labelStatus: UILabel?
259272

260273
private var viewProgress: ProgressView?
261274
private var viewAnimatedIcon: UIView?
262-
private var staticImageView: UIImageView?
275+
private var viewStaticImage: UIImageView?
263276
private var viewAnimation: UIView?
264277

265278
private var animationType = AnimationType.systemActivityIndicator
@@ -505,7 +518,7 @@ private extension ProgressHUD {
505518

506519
if (viewProgress == nil) {
507520
viewProgress = ProgressView(colorProgress)
508-
viewProgress?.frame = CGRect(x: 0, y: 0, width: 70, height: 70)
521+
viewProgress?.frame = CGRect(x: 0, y: 0, width: mediaSize, height: mediaSize)
509522
}
510523

511524
if (viewProgress?.superview == nil) {
@@ -531,7 +544,7 @@ private extension ProgressHUD {
531544
private func setupAnimatedIcon(_ animatedIcon: AnimatedIcon) {
532545

533546
if (viewAnimatedIcon == nil) {
534-
viewAnimatedIcon = UIView(frame: CGRect(x: 0, y: 0, width: 70, height: 70))
547+
viewAnimatedIcon = UIView(frame: CGRect(x: 0, y: 0, width: mediaSize, height: mediaSize))
535548
}
536549

537550
if (viewAnimatedIcon?.superview == nil) {
@@ -555,23 +568,23 @@ private extension ProgressHUD {
555568
//-------------------------------------------------------------------------------------------------------------------------------------------
556569
private func removeStaticImage() {
557570

558-
staticImageView?.removeFromSuperview()
559-
staticImageView = nil
571+
viewStaticImage?.removeFromSuperview()
572+
viewStaticImage = nil
560573
}
561574

562575
//-------------------------------------------------------------------------------------------------------------------------------------------
563576
private func setupStaticImage(_ staticImage: UIImage) {
564577

565-
if (staticImageView == nil) {
566-
staticImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 60, height: 60))
578+
if (viewStaticImage == nil) {
579+
viewStaticImage = UIImageView(frame: CGRect(x: 0, y: 0, width: mediaSize, height: mediaSize))
567580
}
568581

569-
if (staticImageView?.superview == nil) {
570-
toolbarHUD?.addSubview(staticImageView!)
582+
if (viewStaticImage?.superview == nil) {
583+
toolbarHUD?.addSubview(viewStaticImage!)
571584
}
572585

573-
staticImageView?.image = staticImage
574-
staticImageView?.contentMode = .scaleAspectFit
586+
viewStaticImage?.image = staticImage
587+
viewStaticImage?.contentMode = .scaleAspectFit
575588
}
576589
}
577590

@@ -590,7 +603,7 @@ private extension ProgressHUD {
590603
private func setupAnimationView() {
591604

592605
if (viewAnimation == nil) {
593-
viewAnimation = UIView(frame: CGRect(x: 0, y: 0, width: 60, height: 60))
606+
viewAnimation = UIView(frame: CGRect(x: 0, y: 0, width: mediaSize, height: mediaSize))
594607
}
595608

596609
if (viewAnimation?.superview == nil) {
@@ -641,24 +654,15 @@ private extension ProgressHUD {
641654
private func setupSizesBoth(_ text: String) {
642655

643656
var rect = rectText(text)
657+
let base = mediaSize + 2 * marginSize
644658

645-
let marginX: CGFloat = 30
646-
let marginY: CGFloat = 30
659+
let width = max(base, rect.size.width + 2 * marginSize)
660+
let height = max(base, rect.size.height + 2 * marginSize + mediaSize)
647661

648-
let heightA: CGFloat = 60
649-
let marginA: CGFloat = 10
650-
651-
var width = rect.size.width + 2 * marginX
652-
var height = rect.size.height + 2 * marginY + heightA - marginA
653-
654-
if (width < 120) { width = 120 }
655-
656-
let center = CGPoint(x: width / 2, y: marginY + heightA / 2)
662+
let center = CGPoint(x: width / 2, y: marginSize + mediaSize / 2)
657663

658664
rect.origin.x = (width - rect.size.width) / 2
659-
rect.origin.y = (height - rect.size.height) / 2 + heightA - marginA
660-
661-
height += marginA
665+
rect.origin.y = (height - rect.size.height) / 2 + (mediaSize + marginSize) / 2
662666

663667
setupSizes(width, height, center, rect)
664668
}
@@ -667,14 +671,10 @@ private extension ProgressHUD {
667671
private func setupSizesTextOnly(_ text: String) {
668672

669673
var rect = rectText(text)
674+
let base = mediaSize + 2 * marginSize
670675

671-
let marginX: CGFloat = 30
672-
let marginY: CGFloat = 30
673-
674-
var width = rect.size.width + 2 * marginX
675-
let height = rect.size.height + 2 * marginY
676-
677-
if (width < 120) { width = 120 }
676+
let width = max(base, rect.size.width + 2 * marginSize)
677+
let height = max(base, rect.size.height + 2 * marginSize)
678678

679679
rect.origin.x = (width - rect.size.width) / 2
680680
rect.origin.y = (height - rect.size.height) / 2
@@ -685,8 +685,8 @@ private extension ProgressHUD {
685685
//-------------------------------------------------------------------------------------------------------------------------------------------
686686
private func setupSizesTextNone() {
687687

688-
let width: CGFloat = 120
689-
let height: CGFloat = 120
688+
let width = mediaSize + 2 * marginSize
689+
let height = mediaSize + 2 * marginSize
690690

691691
let center = CGPoint(x: width / 2, y: height / 2)
692692

@@ -700,7 +700,7 @@ private extension ProgressHUD {
700700

701701
viewProgress?.center = center
702702
viewAnimatedIcon?.center = center
703-
staticImageView?.center = center
703+
viewStaticImage?.center = center
704704
viewAnimation?.center = center
705705

706706
labelStatus?.frame = rect
@@ -743,7 +743,7 @@ private extension ProgressHUD {
743743

744744
let mainWindow = UIApplication.shared.windows.first ?? UIWindow()
745745
let screen = mainWindow.bounds
746-
let center = CGPoint(x: screen.size.width/2, y: (screen.size.height-heightKeyboard)/2)
746+
let center = CGPoint(x: screen.size.width / 2, y: (screen.size.height - heightKeyboard) / 2)
747747

748748
UIView.animate(withDuration: animationDuration, delay: 0, options: .allowUserInteraction, animations: { [self] in
749749
toolbarHUD?.center = center
@@ -844,11 +844,12 @@ private extension ProgressHUD {
844844
private func animationSystemActivityIndicator(_ view: UIView) {
845845

846846
let spinner = UIActivityIndicatorView(style: .large)
847+
let scale = view.frame.size.width / spinner.frame.size.width
848+
spinner.transform = CGAffineTransform(scaleX: scale, y: scale)
847849
spinner.frame = view.bounds
848850
spinner.color = colorAnimation
849851
spinner.hidesWhenStopped = true
850852
spinner.startAnimating()
851-
spinner.transform = CGAffineTransform(scaleX: 1.75, y: 1.75)
852853
view.addSubview(spinner)
853854
}
854855

@@ -860,7 +861,8 @@ private extension ProgressHUD {
860861

861862
let spacing = 3.0
862863
let radius = (width - spacing * 2) / 3
863-
let ypos = (height - radius) / 2
864+
let center = CGPoint(x: radius / 2, y: radius / 2)
865+
let positionY = (height - radius) / 2
864866

865867
let beginTime = CACurrentMediaTime()
866868
let beginTimes = [0.36, 0.24, 0.12]
@@ -874,11 +876,11 @@ private extension ProgressHUD {
874876
animation.repeatCount = HUGE
875877
animation.isRemovedOnCompletion = false
876878

877-
let path = UIBezierPath(arcCenter: CGPoint(x: radius/2, y: radius/2), radius: radius/2, startAngle: 0, endAngle: 2 * .pi, clockwise: false)
879+
let path = UIBezierPath(arcCenter: center, radius: radius / 2, startAngle: 0, endAngle: 2 * .pi, clockwise: false)
878880

879881
for i in 0..<3 {
880882
let layer = CAShapeLayer()
881-
layer.frame = CGRect(x: (radius + spacing) * CGFloat(i), y: ypos, width: radius, height: radius)
883+
layer.frame = CGRect(x: (radius + spacing) * CGFloat(i), y: positionY, width: radius, height: radius)
882884
layer.path = path.cgPath
883885
layer.fillColor = colorAnimation.cgColor
884886

@@ -909,7 +911,7 @@ private extension ProgressHUD {
909911
animation.repeatCount = HUGE
910912
animation.isRemovedOnCompletion = false
911913

912-
let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: lineWidth, height: height), cornerRadius: width/2)
914+
let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: lineWidth, height: height), cornerRadius: width / 2)
913915

914916
for i in 0..<5 {
915917
let layer = CAShapeLayer()
@@ -930,7 +932,7 @@ private extension ProgressHUD {
930932

931933
let width = view.frame.size.width
932934
let height = view.frame.size.height
933-
let center = CGPoint(x: width/2, y: height/2)
935+
let center = CGPoint(x: width / 2, y: height / 2)
934936
let radius = width / 2
935937

936938
let duration = 1.0
@@ -968,7 +970,7 @@ private extension ProgressHUD {
968970

969971
let width = view.frame.size.width
970972
let height = view.frame.size.height
971-
let center = CGPoint(x: width/2, y: height/2)
973+
let center = CGPoint(x: width / 2, y: height / 2)
972974
let radius = width / 2
973975

974976
let duration = 1.0
@@ -1013,7 +1015,7 @@ private extension ProgressHUD {
10131015

10141016
let width = view.frame.size.width
10151017
let height = view.frame.size.height
1016-
let center = CGPoint(x: width/2, y: height/2)
1018+
let center = CGPoint(x: width / 2, y: height / 2)
10171019
let radius = width / 2
10181020

10191021
let duration = 1.0
@@ -1056,7 +1058,7 @@ private extension ProgressHUD {
10561058

10571059
let width = view.frame.size.width
10581060
let height = view.frame.size.height
1059-
let center = CGPoint(x: width/2, y: height/2)
1061+
let center = CGPoint(x: width / 2, y: height / 2)
10601062
let radius = width / 2
10611063

10621064
let duration = 1.25
@@ -1108,7 +1110,7 @@ private extension ProgressHUD {
11081110
let spacing = 3.0
11091111
let radius = (width - 4 * spacing) / 3.5
11101112
let radiusX = (width - radius) / 2
1111-
let center = CGPoint(x: radius/2, y: radius/2)
1113+
let center = CGPoint(x: radius / 2, y: radius / 2)
11121114

11131115
let duration = 1.0
11141116
let beginTime = CACurrentMediaTime()
@@ -1131,7 +1133,7 @@ private extension ProgressHUD {
11311133
animation.repeatCount = HUGE
11321134
animation.isRemovedOnCompletion = false
11331135

1134-
let path = UIBezierPath(arcCenter: center, radius: radius/2, startAngle: 0, endAngle: 2 * .pi, clockwise: false)
1136+
let path = UIBezierPath(arcCenter: center, radius: radius / 2, startAngle: 0, endAngle: 2 * .pi, clockwise: false)
11351137

11361138
for i in 0..<8 {
11371139
let angle = .pi / 4 * CGFloat(i)
@@ -1174,13 +1176,13 @@ private extension ProgressHUD {
11741176
animation.repeatCount = HUGE
11751177
animation.isRemovedOnCompletion = false
11761178

1177-
let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: lineWidth, height: lineHeight), cornerRadius: lineWidth/2)
1179+
let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: lineWidth, height: lineHeight), cornerRadius: lineWidth / 2)
11781180

11791181
for i in 0..<8 {
11801182
let angle = .pi / 4 * CGFloat(i)
11811183

11821184
let line = CAShapeLayer()
1183-
line.frame = CGRect(x: (containerSize-lineWidth)/2, y: (containerSize-lineHeight)/2, width: lineWidth, height: lineHeight)
1185+
line.frame = CGRect(x: (containerSize - lineWidth) / 2, y: (containerSize - lineHeight) / 2, width: lineWidth, height: lineHeight)
11841186
line.path = path.cgPath
11851187
line.backgroundColor = nil
11861188
line.fillColor = colorAnimation.cgColor
@@ -1202,16 +1204,16 @@ private extension ProgressHUD {
12021204

12031205
let width = view.frame.size.width
12041206
let height = view.frame.size.height
1205-
let center = CGPoint(x: width/2, y: height/2)
1207+
let center1 = CGPoint(x: width / 2, y: height / 2)
12061208

12071209
let spacing = 3.0
1208-
let radius = (width - 4 * spacing) / 3.5
1210+
let radius = (width - 4 * spacing) / 4
1211+
let center2 = CGPoint(x: radius / 2, y: radius / 2)
12091212

12101213
let duration = 1.5
12111214

1212-
let path = UIBezierPath(arcCenter: CGPoint(x: radius/2, y: radius/2), radius: radius/2, startAngle: 0, endAngle: 2 * .pi, clockwise: false)
1213-
1214-
let pathPosition = UIBezierPath(arcCenter: center, radius: radius*2, startAngle: 1.5 * .pi, endAngle: 3.5 * .pi, clockwise: true)
1215+
let path1 = UIBezierPath(arcCenter: center1, radius: radius * 2, startAngle: 1.5 * .pi, endAngle: 3.5 * .pi, clockwise: true)
1216+
let path2 = UIBezierPath(arcCenter: center2, radius: radius / 2, startAngle: 0, endAngle: 2 * .pi, clockwise: false)
12151217

12161218
for i in 0..<5 {
12171219
let rate = Float(i) * 1 / 5
@@ -1228,7 +1230,7 @@ private extension ProgressHUD {
12281230
let animationPosition = CAKeyframeAnimation(keyPath: "position")
12291231
animationPosition.duration = duration
12301232
animationPosition.repeatCount = HUGE
1231-
animationPosition.path = pathPosition.cgPath
1233+
animationPosition.path = path1.cgPath
12321234

12331235
let animation = CAAnimationGroup()
12341236
animation.animations = [animationScale, animationPosition]
@@ -1239,7 +1241,7 @@ private extension ProgressHUD {
12391241

12401242
let layer = CAShapeLayer()
12411243
layer.frame = CGRect(x: 0, y: 0, width: radius, height: radius)
1242-
layer.path = path.cgPath
1244+
layer.path = path2.cgPath
12431245
layer.fillColor = colorAnimation.cgColor
12441246

12451247
layer.add(animation, forKey: "animation")
@@ -1252,7 +1254,7 @@ private extension ProgressHUD {
12521254

12531255
let width = view.frame.size.width
12541256
let height = view.frame.size.height
1255-
let center = CGPoint(x: width/2, y: height/2)
1257+
let center = CGPoint(x: width / 2, y: height / 2)
12561258

12571259
let beginTime = 0.5
12581260
let durationStart = 1.2
@@ -1282,7 +1284,7 @@ private extension ProgressHUD {
12821284
animation.isRemovedOnCompletion = false
12831285
animation.fillMode = .forwards
12841286

1285-
let path = UIBezierPath(arcCenter: center, radius: width/2, startAngle: -0.5 * .pi, endAngle: 1.5 * .pi, clockwise: true)
1287+
let path = UIBezierPath(arcCenter: center, radius: width / 2, startAngle: -0.5 * .pi, endAngle: 1.5 * .pi, clockwise: true)
12861288

12871289
let layer = CAShapeLayer()
12881290
layer.frame = CGRect(x: 0, y: 0, width: width, height: height)
@@ -1462,8 +1464,8 @@ private class ProgressView: UIView {
14621464

14631465
let width = frame.size.width
14641466
let height = frame.size.height
1467+
let center = CGPoint(x: width / 2, y: height / 2)
14651468

1466-
let center = CGPoint(x: width/2, y: height/2)
14671469
let radiusCircle = width / 2
14681470
let radiusProgress = width / 2 - 5
14691471

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@
44

55
<img src="https://related.chat/hud/001.gif" width="80"> <img src="https://related.chat/hud/002.gif" width="80"> <img src="https://related.chat/hud/003.gif" width="80"> <img src="https://related.chat/hud/004.gif" width="80"> <img src="https://related.chat/hud/005.gif" width="80"> <img src="https://related.chat/hud/006.gif" width="80"> <img src="https://related.chat/hud/007.gif" width="80"> <img src="https://related.chat/hud/008.gif" width="80"> <img src="https://related.chat/hud/009.gif" width="80"> <img src="https://related.chat/hud/010.gif" width="80"> <img src="https://related.chat/hud/011.gif" width="80"> <img src="https://related.chat/hud/011.png" width="80"> <img src="https://related.chat/hud/012.gif" width="80"> <img src="https://related.chat/hud/012.png" width="80"> <img src="https://related.chat/hud/013.gif" width="80"> <img src="https://related.chat/hud/013.png" width="80"> <img src="https://related.chat/hud/014.gif" width="80"> <img src="https://related.chat/hud/014.png" width="80"> <img src="https://related.chat/hud/015.gif" width="80"> <img src="https://related.chat/hud/015.png" width="80">
66

7-
## WHAT'S NEW IN 13.7.0
7+
## WHAT'S NEW
8+
9+
### Version: 13.7.1
10+
11+
- The `mediaSize` and `marginSize` options are now available to adjust the HUD dimensions.
12+
13+
### Version: 13.7.0
814

915
- New `AnimationType.none` has been implemented. So you can display some text without animation.
1016

11-
## WHAT'S NEW IN 13.6.2
17+
### Version: 13.6.2
1218

1319
- We have the optional `delay:` parameter to set the timeout.
1420
- We have the `.remove()` function to dismiss the HUD immediately.
1521

16-
## WHAT'S NEW IN 13.5 and 13.6
22+
### Version: 13.5 and 13.6
1723

1824
- Bugfix related to iPad split screen.
1925
- Bugfix related to showProgress.
@@ -118,6 +124,11 @@ ProgressHUD.colorProgress = .systemBlue
118124
ProgressHUD.colorStatus = .label
119125
```
120126

127+
```swift
128+
ProgressHUD.mediaSize = 100
129+
ProgressHUD.marginSize = 50
130+
```
131+
121132
```swift
122133
ProgressHUD.fontStatus = .boldSystemFont(ofSize: 24)
123134
```

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13.7.0
1+
13.7.1

0 commit comments

Comments
 (0)