From 95359781ef7986750e569d854a280eefe5e33abd Mon Sep 17 00:00:00 2001 From: Pizzo15 Date: Sat, 27 Mar 2021 15:33:14 +0100 Subject: [PATCH 1/2] Added documentation for MultiProgressViewDataSource and MultiProgressViewDelegate as asked in #42 --- README.md | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1711f7e..fd96e45 100644 --- a/README.md +++ b/README.md @@ -66,12 +66,18 @@ To run the example project, clone the repo and run the `MultiProgressViewExample func numberOfSections(in progressView: MultiProgressView) -> Int func progressView(_ progressView: MultiProgressView, viewForSection section: Int) -> ProgressViewSection ``` - + 5. Set your view controller as the progress view's `dataSource`: ![DataSource](https://raw.githubusercontent.com/mac-gallagher/MultiProgressView/master/Images/storyboard_data_source.gif) + +6. (Optional) Conform your view controller to the `MultiProgressViewDelegate` protocol and implement the required method if you need to add a tap gesture recognizer to your `MultiProgressView` instance: -6. Call `setProgress(section:to:)` to update your view's progress: + ```swift + func progressView(_ progressView: MultiProgressView, didTapSectionAt index: Int) + ``` + +7. Call `setProgress(section:to:)` to update your view's progress: ```swift progressView.setProgress(section: 0, to: 0.4) //animatable @@ -114,6 +120,34 @@ var titleEdgeInsets: UIEdgeInsets = .zero var titleAlignment: AlignmentType = .center ``` +### Data Source +Each `MultiProgressView` needs to conform to the `MultiProgressViewDataSource` protocol: + +```swift +func numberOfSections(in progressView: MultiProgressView) -> Int { + return 1 // Return the number of section of your MultiProgressView +} + +func progressView(_ progressView: MultiProgressView, viewForSection section: Int) -> ProgressViewSection { + guard let progressView = progressView as? CustomProgressView() else { return ProgressViewSection() } + + // Customize your progressView here... + + return progressView + } +``` + +### Delegate +Optionally, a `MultiProgressView` can conform to the `MultiProgressViewDelegate` protocol, which define a method to recognize a tap event on `MultiProgressView`'s sections: + +```swift +func progressView(_ progressView: MultiProgressView, didTapSectionAt index: Int) { + for (progressViewIndex, view) in progressViews.enumerated() where view === progressView { + print("Tapped progressView \(progressViewIndex) at section \(index)") + } +} +``` + ## Installation ### CocoaPods From 0082f067b8904bcc9ae66d92ed02aa7c06935623 Mon Sep 17 00:00:00 2001 From: Pizzo15 Date: Sat, 27 Mar 2021 15:35:51 +0100 Subject: [PATCH 2/2] Added documentation for MultiProgressViewDataSource and MultiProgressViewDelegate as asked in #42 --- README.md | 58 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index fd96e45..378119e 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,36 @@ To run the example project, clone the repo and run the `MultiProgressViewExample progressView.setProgress(section: 0, to: 0.4) //animatable ``` +## Data Source +Each `MultiProgressView` needs to conform to the `MultiProgressViewDataSource` protocol: + +```swift +func numberOfSections(in progressView: MultiProgressView) -> Int { + return 1 // Return the number of section of your MultiProgressView +} + +func progressView(_ progressView: MultiProgressView, viewForSection section: Int) -> ProgressViewSection { + guard let progressView = progressView as? CustomProgressView() else { return ProgressViewSection() } + + // Customize your progressView here... + + return progressView +} +``` + +## Delegate + +Optionally, a `MultiProgressView` can conform to the `MultiProgressViewDelegate` protocol, which define a method to recognize a tap event on `MultiProgressView`'s sections: + +```swift +func progressView(_ progressView: MultiProgressView, didTapSectionAt index: Int) { + for (progressViewIndex, view) in progressViews.enumerated() where view === progressView { + print("Tapped progressView \(progressViewIndex) at section \(index)") + } +} +``` + + ## Customization ### MultiProgressView @@ -120,34 +150,6 @@ var titleEdgeInsets: UIEdgeInsets = .zero var titleAlignment: AlignmentType = .center ``` -### Data Source -Each `MultiProgressView` needs to conform to the `MultiProgressViewDataSource` protocol: - -```swift -func numberOfSections(in progressView: MultiProgressView) -> Int { - return 1 // Return the number of section of your MultiProgressView -} - -func progressView(_ progressView: MultiProgressView, viewForSection section: Int) -> ProgressViewSection { - guard let progressView = progressView as? CustomProgressView() else { return ProgressViewSection() } - - // Customize your progressView here... - - return progressView - } -``` - -### Delegate -Optionally, a `MultiProgressView` can conform to the `MultiProgressViewDelegate` protocol, which define a method to recognize a tap event on `MultiProgressView`'s sections: - -```swift -func progressView(_ progressView: MultiProgressView, didTapSectionAt index: Int) { - for (progressViewIndex, view) in progressViews.enumerated() where view === progressView { - print("Tapped progressView \(progressViewIndex) at section \(index)") - } -} -``` - ## Installation ### CocoaPods