Skip to content

Commit 414d121

Browse files
committed
📝 :: Update documentation
1 parent 692d9aa commit 414d121

1 file changed

Lines changed: 116 additions & 83 deletions

File tree

readme.md

Lines changed: 116 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,156 @@
1-
GradientLoadingBar
2-
====================
1+
# Gradient Loading Bar
32

4-
![Swift5.0](https://img.shields.io/badge/Swift-5.0-green.svg?style=flat) ![CI Status](https://img.shields.io/github/workflow/status/fxm90/GradientLoadingBar/Continuous%20Integration) ![Code Coverage](https://img.shields.io/codecov/c/github/fxm90/GradientLoadingBar.svg?style=flat) ![Version](https://img.shields.io/cocoapods/v/GradientLoadingBar.svg?style=flat) ![License](https://img.shields.io/cocoapods/l/GradientLoadingBar.svg?style=flat) ![Platform](https://img.shields.io/cocoapods/p/GradientLoadingBar.svg?style=flat)
3+
![Swift6.2](https://img.shields.io/badge/Swift-6.2-green.svg?style=flat) ![CI Status](https://img.shields.io/github/actions/workflow/status/fxm90/GradientLoadingBar/continuous-integration.yml?branch=feature/version-4) ![Code Coverage](https://img.shields.io/codecov/c/github/fxm90/GradientLoadingBar.svg?style=flat) ![Version](https://img.shields.io/github/v/release/fxm90/GradientLoadingBar) ![License](https://img.shields.io/github/license/fxm90/GradientLoadingBar?color=333333) ![Platform](https://img.shields.io/badge/platform-iOS-8a8a8a)
54

6-
A customizable animated gradient loading bar. Inspired by [iOS 7 Progress Bar from Codepen](https://codepen.io/marcobiedermann/pen/LExXWW).
5+
A customizable animated gradient loading bar, with support for **SwiftUI** and **UIKit**.\
6+
Inspired by [iOS 7 Progress Bar on Codepen](https://codepen.io/marcobiedermann/pen/LExXWW).
7+
8+
### Screenshot
79

8-
### Example
910
![Example][example]
1011

11-
To run the example project, clone the repo, and open the workspace from the Example directory.
12+
To run the example project, clone this repository and open the project from the **Example** directory.
1213

13-
### Requirements
14-
- Swift 5.5
15-
- Xcode 13
16-
- iOS 13.0+
14+
## Requirements
1715

18-
**Note:** In case you need support for iOS versions lower than 13, you can fallback to version `2.X.X`.
16+
- Swift **6.2**
17+
- Xcode **26**
18+
- iOS **26.0+**
1919

20+
### Compatibility Notes
2021

21-
### Integration
22-
##### CocoaPods
23-
[CocoaPods](https://cocoapods.org) is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate GradientLoadingBar into your Xcode project using CocoaPods, specify it in your `Podfile`:
22+
- **iOS < 26.0 / CocoaPods / Carthage support**
23+
Use version **`3.x.x`**
24+
- **iOS < 13.0 support**
25+
Use version **`2.x.x`**
2426

25-
```ruby
26-
pod 'GradientLoadingBar', '~> 3.0'
27-
```
27+
## Installation
2828

29-
##### Carthage
30-
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate GradientLoadingBar into your Xcode project using Carthage, specify it in your `Cartfile`:
29+
### Swift Package Manager
3130

32-
```ogdl
33-
github "fxm90/GradientLoadingBar" ~> 3.0
34-
```
35-
Run carthage update to build the framework and drag the built `GradientLoadingBar.framework` into your Xcode project.
31+
**Gradient Loading Bar** is distributed via **Swift Package Manager (SPM)**. Add it to your Xcode project as a package dependency or adapt your `Package.swift` file.
32+
33+
#### Option 1: Xcode
3634

35+
1. Open your project in **Xcode**
36+
2. Go to **File → Add Packages…**
37+
3. Enter the package URL: `https://github.com/fxm90/GradientLoadingBar`
38+
4. Choose the version rule (e.g. _Up to Next Major_ starting at **4.0.0**)
39+
5. Add the package to your target
3740

38-
##### Swift Package Manager
39-
The [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. It is in early development, but Gradient Loading Bar does support its use on supported platforms.
41+
#### Option 2: `Package.swift`
4042

41-
Once you have your Swift package set up, adding Gradient Loading Bar as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.
43+
If you manage dependencies manually, add this repository to the `dependencies` section of your `Package.swift`:
4244

4345
```swift
4446
dependencies: [
45-
.package(url: "https://github.com/fxm90/GradientLoadingBar", from: "3.0.0")
47+
.package(
48+
url: "https://github.com/fxm90/GradientLoadingBar",
49+
from: "4.0.0"
50+
)
4651
]
4752
```
4853

54+
Then reference the product in your target configuration:
55+
56+
```swift
57+
.product(
58+
name: "GradientLoadingBar",
59+
package: "GradientLoadingBar"
60+
)
61+
```
62+
63+
Once the package is added, import the framework where needed:
64+
65+
```swift
66+
import GradientLoadingBar
67+
```
4968

5069
### How to use
70+
5171
This framework provides four classes:
5272

53-
- **GradientLoadingBar**: A controller, managing the visibility of the `GradientActivityIndicatorView` on the current key window.
54-
- **NotchGradientLoadingBar**: A subclass of `GradientLoadingBar`, wrapping the `GradientActivityIndicatorView` around the notch of the iPhone.
55-
- **GradientActivityIndicatorView**: A `UIView` containing the gradient with the animation. It can be added as a subview to another view either inside the interface builder or programmatically. Both ways are shown inside the example application.
56-
- **GradientLoadingBarView**: A `View` for SwiftUI containing the gradient with the animation. The view can be added to any other SwiftUI view. The example application also contains sample code for this use case.
73+
- **GradientLoadingBar**: A controller, managing the visibility of the `GradientActivityIndicatorView` on the current key window.
74+
- **NotchGradientLoadingBar**: A subclass of `GradientLoadingBar`, wrapping the `GradientActivityIndicatorView` around the notch of the iPhone.
75+
- **GradientActivityIndicatorView**: A `UIView` containing the gradient with the animation. It can be added as a subview to another view either inside the interface builder or programmatically. Both ways are shown inside the example application.
76+
- **GradientLoadingBarView**: A `View` for SwiftUI containing the gradient with the animation. The view can be added to any other SwiftUI view. The example application also contains sample code for this use case.
5777

5878
#### GradientLoadingBar
59-
To get started, import the module `GradientLoadingBar` into your file and save an instance of `GradientLoadingBar()` on a property of your view-controller. To show the loading bar, simply call the `fadeIn(duration:completion)` method and after your async operations have finished call the `fadeOut(duration:completion)` method.
79+
80+
To get started, import the module `GradientLoadingBar` into your file and save an instance of `GradientLoadingBar()` on a property of your view-controller. To show the loading bar, simply call the `fadeIn(duration:completion)` method and after your async operations have finished call the `fadeOut(duration:completion)` method.
6081

6182
```swift
6283
final class UserViewController: UIViewController {
6384

64-
private let gradientLoadingBar = GradientLoadingBar()
85+
private let gradientLoadingBar = GradientLoadingBar()
6586

66-
// ...
87+
// ...
6788

68-
override func viewDidLoad() {
69-
super.viewDidLoad()
89+
override func viewDidLoad() {
90+
super.viewDidLoad()
7091

71-
gradientLoadingBar.fadeIn()
92+
gradientLoadingBar.fadeIn()
7293

73-
userService.loadUserData { [weak self] _ in
74-
// ...
75-
// Be sure to call this on the main thread!
76-
self?.gradientLoadingBar.fadeOut()
77-
}
94+
userProfileService.fetchUserProfile { [weak self] _ in
95+
// ...
96+
// Be sure to call this on the main actor!
97+
self?.gradientLoadingBar.fadeOut()
7898
}
99+
}
79100
}
80101
```
81102

82103
##### Configuration
104+
83105
You can override the default configuration by calling the initializers with the optional parameters `height` and `isRelativeToSafeArea`:
84106

85107
```swift
86108
let gradientLoadingBar = GradientLoadingBar(
87-
height: 4.0,
88-
isRelativeToSafeArea: true
109+
height: 4.0,
110+
isRelativeToSafeArea: true
89111
)
90112
```
91113

92114
###### – Parameter `height: CGFloat`
115+
93116
By setting this parameter you can set the height for the loading bar (defaults to `3.0`)
94117

95118
###### – Parameter `isRelativeToSafeArea: Bool`
119+
96120
With this parameter you can configure, whether the loading bar should be positioned relative to the safe area (defaults to `true`).
97121

98122
Example with `isRelativeToSafeArea` set to `true`.
99123
[![Example][basic-example--thumbnail]][basic-example]
100124

101-
102125
Example with `isRelativeToSafeArea` set to `false`.
103126
[![Example][safe-area-example--thumbnail]][safe-area-example]
104127

105128
##### Note
129+
106130
There is a third option which will wrap the loading bar around the iPhone notch. See documentation of the class `NotchGradientLoadingBar` for further details.
107131

108132
##### Properties
133+
109134
###### `gradientColors: [UIColor]`
135+
110136
This property adjusts the gradient colors shown on the loading bar.
111137

112138
###### `progressAnimationDuration: TimeInterval`
139+
113140
This property adjusts the duration of the animation moving the gradient from left to right.
114141

115142
##### Methods
143+
116144
###### `fadeIn(duration:completion)`
145+
117146
This method fades-in the loading bar. You can adjust the duration with corresponding parameter. Furthermore you can pass in a completion handler that gets called once the animation is finished.
118147

119148
###### `fadeOut(duration:completion)`
120-
This methods fades-out the loading bar. You can adjust the duration with corresponding parameter. Furthermore you can pass in a completion handler that gets called once the animation is finished.
149+
150+
This methods fades-out the loading bar. You can adjust the duration with corresponding parameter. Furthermore you can pass in a completion handler that gets called once the animation is finished.
121151

122152
##### Custom shared instance (Singleton)
153+
123154
If you need the loading bar on multiple / different parts of your app, you can use the given static `shared` variable:
124155

125156
```swift
@@ -136,119 +167,121 @@ If you wish to customize the shared instance, you can add the following code e.g
136167
GradientLoadingBar.shared = GradientLoadingBar(height: 5.0)
137168
```
138169

139-
140170
#### NotchGradientLoadingBar
171+
141172
This subclass of the `GradientLoadingBar` will wrap the loading bar around the notch of the iPhone.
142173

143174
For iPhones without a safe area, the behaviour stays the same as mentioned in the above documentation of the `GradientLoadingBar`.
144175

145176
```swift
146177
let notchGradientLoadingBar = NotchGradientLoadingBar(
147-
height: 3.0
178+
height: 3.0
148179
)
149180
```
150181

151182
[![Example][notch-example--thumbnail]][notch-example]
152183

153184
#### GradientActivityIndicatorView
185+
154186
In case you don't want to add the loading bar onto the key-window, this framework provides the `GradientActivityIndicatorView`, which is a direct subclass of `UIView`. You can add the view to another view either inside the interface builder or programmatically.
155187

156188
E.g. View added as a subview to a `UINavigationBar`.
157189
[![Example][navigation-bar-example--thumbnail]][navigation-bar-example]
158190

159-
160191
E.g. View added as a subview to a `UIButton`.
161192
[![Example][advanced-example--thumbnail]][advanced-example]
162193

163194
##### Note
195+
164196
The progress-animation starts and stops according to the `isHidden` flag. Setting this flag to `false` will start the animation, setting this to `true` will stop the animation. Often you don't want to directly show / hide the view and instead smoothly fade it in or out. Therefore the view provides the methods `fadeIn(duration:completion)` and `fadeOut(duration:completion)`. Based on the gist [`UIView+AnimateAlpha.swift`](https://gist.github.com/fxm90/723b5def31b46035cd92a641e3b184f6), these methods adjust the `alpha` value of the view and update the `isHidden` flag accordingly.
165197

166198
##### Properties
199+
167200
###### `gradientColors: [UIColor]`
201+
168202
This property adjusts the gradient colors shown on the loading bar.
169203

170204
###### `progressAnimationDuration: TimeInterval`
171-
This property adjusts the duration of the animation moving the gradient from left to right.
172205

173-
*To see all these screenshots in a real app, please have a look at the **example application**. For further customization you can also subclass `GradientLoadingBar` and overwrite the method `setupConstraints()`.*
206+
This property adjusts the duration of the animation moving the gradient from left to right.
174207

208+
_To see all these screenshots in a real app, please have a look at the **example application**. For further customization you can also subclass `GradientLoadingBar` and overwrite the method `setupConstraints()`._
175209

176210
#### GradientLoadingBarView
211+
177212
This is the SwiftUI variant for the `GradientActivityIndicatorView`. The view can be configured via the two parameters `gradientColors: [Color]` and `progressDuration: TimeInterval` passed to the initializer.
178213

179214
##### `gradientColors: [Color]` :
215+
180216
This parameter adjusts the gradient colors shown on the loading bar.
181217

182218
##### `progressDuration: TimeInterval` :
219+
183220
This parameter adjusts the duration of the animation moving the gradient from left to right.
184221

185-
The visibility of the view can be updated with the view modifier [`opacity()`](https://developer.apple.com/documentation/swiftui/view/opacity(_:)) or [`hidden()`](https://developer.apple.com/documentation/swiftui/view/hidden()).
222+
The visibility of the view can be updated with the view modifier [`opacity()`](<https://developer.apple.com/documentation/swiftui/view/opacity(_:)>) or [`hidden()`](<https://developer.apple.com/documentation/swiftui/view/hidden()>).
186223

187-
To animate the visibility changes you need to create a property with the `@State` property wrapper, and update the value from a [`withAnimation`](https://developer.apple.com/documentation/swiftui/withanimation(_:_:)) block, e.g.
224+
To animate the visibility changes you need to create a property with the `@State` property wrapper, and update the value from a [`withAnimation`](<https://developer.apple.com/documentation/swiftui/withanimation(_:_:)>) block, e.g.
188225

189226
```swift
190227
struct ExampleView: some View {
191228

192-
@State
193-
private var isVisible = false
194-
195-
var body: some View {
196-
VStack {
197-
GradientLoadingBarView()
198-
.frame(maxWidth: .infinity, maxHeight: 3)
199-
.cornerRadius(1.5)
200-
.opacity(isVisible ? 1 : 0)
201-
202-
Button("Toggle visibility") {
203-
withAnimation(.easeInOut) {
204-
isVisible.toggle()
205-
}
206-
}
229+
@State
230+
private var isVisible = false
231+
232+
var body: some View {
233+
VStack {
234+
GradientLoadingBarView()
235+
.frame(maxWidth: .infinity, maxHeight: 3)
236+
.cornerRadius(1.5)
237+
.opacity(isVisible ? 1 : 0)
238+
239+
Button("Toggle visibility") {
240+
withAnimation(.easeInOut) {
241+
isVisible.toggle()
207242
}
243+
}
208244
}
245+
}
209246
}
210247
```
211248

212-
213249
### Troubleshooting
250+
214251
#### Interface Builder Support
252+
215253
Unfortunately the Interface Builder support is currently broken for Cocoapods frameworks. If you need Interface Builder support, add the following code to your Podfile and run `pod install` again. Afterwards you should be able to use the `GradientLoadingBar` inside the Interface Builder :)
216254

217255
```
218256
post_install do |installer|
219-
installer.pods_project.build_configurations.each do |config|
220-
next unless config.name == 'Debug'
257+
installer.pods_project.build_configurations.each do |config|
258+
next unless config.name == 'Debug'
221259
222-
config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = [
223-
'$(FRAMEWORK_SEARCH_PATHS)'
224-
]
225-
end
260+
config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = [
261+
'$(FRAMEWORK_SEARCH_PATHS)'
262+
]
226263
end
227-
```
228-
Source: [Cocoapods – Issue 7606](https://github.com/CocoaPods/CocoaPods/issues/7606#issuecomment-484294739)
264+
end
265+
```
229266

267+
Source: [Cocoapods – Issue 7606](https://github.com/CocoaPods/CocoaPods/issues/7606#issuecomment-484294739)
230268

231269
### Author
270+
232271
Felix Mau (me(@)felix.hamburg)
233272

234273
### License
235274

236275
GradientLoadingBar is available under the MIT license. See the LICENSE file for more info.
237276

238277
[example]: Assets/screen.gif
239-
240278
[basic-example]: Assets/basic-example.png
241279
[basic-example--thumbnail]: Assets/basic-example--thumbnail.png
242-
243280
[safe-area-example]: Assets/safe-area-example.png
244281
[safe-area-example--thumbnail]: Assets/safe-area-example--thumbnail.png
245-
246282
[notch-example]: Assets/notch-example.png
247283
[notch-example--thumbnail]: Assets/notch-example--thumbnail.png
248-
249284
[navigation-bar-example]: Assets/navigation-bar-example.png
250285
[navigation-bar-example--thumbnail]: Assets/navigation-bar-example--thumbnail.png
251-
252-
253286
[advanced-example]: Assets/advanced-example.png
254287
[advanced-example--thumbnail]: Assets/advanced-example--thumbnail.png

0 commit comments

Comments
 (0)