Skip to content

Commit

Permalink
Merge pull request #8 from DeluxeAlonso/development
Browse files Browse the repository at this point in the history
Development to master for 1.2.0 version
  • Loading branch information
DeluxeAlonso authored Apr 10, 2021
2 parents e4b02c5 + 2368227 commit b0695c4
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 49 deletions.
2 changes: 1 addition & 1 deletion DLAutoSlidePageViewController.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'DLAutoSlidePageViewController'
s.version = '1.1.0'
s.version = '1.2.0'
s.summary = 'An auto slide PageViewController.'

s.description = <<-DESC
Expand Down
14 changes: 0 additions & 14 deletions Example/DLAutoSlidePageViewController/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -20,23 +19,13 @@
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="03X-Cc-7LE">
<rect key="frame" x="0.0" y="167" width="375" height="333.5"/>
</containerView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="c9l-1t-INW" customClass="MaterialPageControl" customModule="MaterialPageControl">
<rect key="frame" x="16" y="516.5" width="343" height="36"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="36" id="87w-Bn-eJm"/>
</constraints>
</view>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="03X-Cc-7LE" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="3A5-5m-yXg"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="c9l-1t-INW" secondAttribute="trailing" constant="16" id="8ve-yq-Gok"/>
<constraint firstItem="03X-Cc-7LE" firstAttribute="height" secondItem="8bC-Xf-vdC" secondAttribute="height" multiplier="0.5" id="dA5-qs-oV0"/>
<constraint firstItem="c9l-1t-INW" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="lVF-cP-mp8"/>
<constraint firstItem="03X-Cc-7LE" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="pO2-JF-GZK"/>
<constraint firstItem="c9l-1t-INW" firstAttribute="top" secondItem="03X-Cc-7LE" secondAttribute="bottom" constant="16" id="vpa-WI-6tY"/>
<constraint firstItem="03X-Cc-7LE" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="width" id="yda-Gc-UoF"/>
</constraints>
</view>
Expand Down Expand Up @@ -81,8 +70,5 @@
</scenes>
<resources>
<image name="ChromeIcon" width="150" height="150"/>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pod "DLAutoSlidePageViewController"
To integrate using [Swift Package Manager](https://swift.org/package-manager/), add the following as a dependency to your Package.swift:

```Swift
.package(url: "https://github.com/DeluxeAlonso/DLAutoSlidePageViewController.git", .upToNextMajor(from: "1.1.0"))
.package(url: "https://github.com/DeluxeAlonso/DLAutoSlidePageViewController.git", .upToNextMajor(from: "1.2.0"))
```

## Usage
Expand Down Expand Up @@ -81,15 +81,20 @@ let pages = [firstVC, secondVC]
let pageViewController = DLAutoSlidePageViewController(pages: pages, configuration: CustomConfiguration())
```

## Page control configuration
## Available configuration properties

You can also access the UIPageControl through the `pageControl` property.
`DLAutoSlidePageViewController` can be customized via the following properties:

```swift
pageViewController.pageControl.currentPageIndicatorTintColor = UIColor.lightGray
pageViewController.pageControl.pageIndicatorTintColor = UIColor.gray
pageViewController.pageControl.backgroundColor = UIColor.clear
```
| Property | Type | Description |
|:----------:|:-------------:|------|
| timeInterval | TimeInterval | Time interval to be used for each page automatic transition. |
| transitionStyle | UIPageViewController.TransitionStyle | Styles for the page-turn transition. |
| navigationOrientation | UIPageViewController.NavigationOrientation | Orientations for page-turn transitions. |
| interPageSpacing | Float | Space between pages. |
| hidePageControl | Bool | Decides if page contron is going to be shown or not. |
| currentPageIndicatorTintColor | UIColor | The tint color to be used for the current page indicator. |
| pageIndicatorTintColor | UIColor | The tint color to be used for the page indicator. |
| pageControlBackgroundColor | UIColor | The background color to be used for the page control. |

## Author

Expand Down
22 changes: 22 additions & 0 deletions Sources/AutoSlideConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,30 @@ import UIKit

public protocol AutoSlideConfiguration {

/// Time interval to be used for each page automatic transition.
var timeInterval: TimeInterval { get }

/// Styles for the page-turn transition.
var transitionStyle: UIPageViewController.TransitionStyle { get }

/// Orientations for page-turn transitions.
var navigationOrientation: UIPageViewController.NavigationOrientation { get }

/// Space between pages.
var interPageSpacing: Float { get }

/// Decides if page contron is going to be shown or not.
var hidePageControl: Bool { get }

/// The tint color to be used for the current page indicator.
var currentPageIndicatorTintColor: UIColor { get }

/// The tint color to be used for the page indicator.
var pageIndicatorTintColor: UIColor { get }

/// The background color to be used for the page control.
var pageControlBackgroundColor: UIColor { get }

}

// MARK: - Default values
Expand All @@ -27,4 +45,8 @@ public extension AutoSlideConfiguration {
var interPageSpacing: Float { 0.0 }
var hidePageControl: Bool { false }

var currentPageIndicatorTintColor: UIColor { UIColor.gray }
var pageIndicatorTintColor: UIColor { UIColor.lightGray }
var pageControlBackgroundColor: UIColor { UIColor.clear }

}
55 changes: 29 additions & 26 deletions Sources/DLAutoSlidePageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,12 @@ open class DLAutoSlidePageViewController: UIPageViewController {
fileprivate var transitionInProgress: Bool = false
fileprivate var shouldHidePageControl: Bool = false

// MARK: - Computed properties

public var pageControl: UIPageControl? {
return UIPageControl.appearance(whenContainedInInstancesOf: [UIPageViewController.self])
}

// MARK: - Lifecycle

deinit {
stopTimer()
NotificationCenter.default.removeObserver(self,
name: UIApplication.willEnterForegroundNotification,
object: nil);
}

override open func viewDidLoad() {
super.viewDidLoad()
delegate = self
dataSource = self
setupObservers()
}

// MARK: - Initializers

public convenience init(pages: [UIViewController],
Expand All @@ -51,7 +37,8 @@ open class DLAutoSlidePageViewController: UIPageViewController {
self.shouldHidePageControl = configuration.hidePageControl

setupPageView()
setupPageControl()
setupPageTimer(with: timeInterval)
setupPageControl(with: configuration)
}

public convenience init(pages: [UIViewController],
Expand All @@ -66,7 +53,24 @@ open class DLAutoSlidePageViewController: UIPageViewController {
self.timeInterval = ti
self.shouldHidePageControl = hidePageControl
setupPageView()
setupPageControl()
setupPageTimer(with: timeInterval)
setupPageControl(with: DefaultAutoSlideConfiguration.shared)
}

// MARK: - Lifecycle

deinit {
stopTimer()
NotificationCenter.default.removeObserver(self,
name: UIApplication.willEnterForegroundNotification,
object: nil);
}

override open func viewDidLoad() {
super.viewDidLoad()
delegate = self
dataSource = self
setupObservers()
}

// MARK: - Private
Expand All @@ -82,11 +86,10 @@ open class DLAutoSlidePageViewController: UIPageViewController {
setViewControllers([firstPage], direction: .forward, animated: true, completion: nil)
}

fileprivate func setupPageControl() {
if self.timeInterval != 0.0 { setupPageTimer() }
pageControl?.currentPageIndicatorTintColor = UIColor.gray
pageControl?.pageIndicatorTintColor = UIColor.lightGray
pageControl?.backgroundColor = UIColor.clear
fileprivate func setupPageControl(with configuration: AutoSlideConfiguration) {
pageControl?.currentPageIndicatorTintColor = configuration.currentPageIndicatorTintColor
pageControl?.pageIndicatorTintColor = configuration.pageIndicatorTintColor
pageControl?.backgroundColor = configuration.pageControlBackgroundColor
}

fileprivate func viewControllerAtIndex(_ index: Int) -> UIViewController {
Expand All @@ -95,7 +98,8 @@ open class DLAutoSlidePageViewController: UIPageViewController {
return pages[index]
}

fileprivate func setupPageTimer() {
fileprivate func setupPageTimer(with timeInterval: TimeInterval) {
guard timeInterval != 0.0 else { return }
timer = Timer.scheduledTimer(timeInterval: timeInterval,
target: self,
selector: #selector(changePage),
Expand All @@ -110,9 +114,8 @@ open class DLAutoSlidePageViewController: UIPageViewController {
}

fileprivate func restartTimer() {
guard timeInterval != 0.0 else { return }
stopTimer()
setupPageTimer()
setupPageTimer(with: timeInterval)
}

// MARK: - Selectors
Expand Down

0 comments on commit b0695c4

Please sign in to comment.