Skip to content

Commit

Permalink
Merge pull request #6 from redbooth/controllerToViewRefactor
Browse files Browse the repository at this point in the history
Controller to view refactor
  • Loading branch information
twof authored Jan 4, 2019
2 parents db158ff + 1fdeeae commit 92a45db
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 108 deletions.
4 changes: 4 additions & 0 deletions MyPlayground.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ let pagedView = SimplePagedView(
with: green, red, orange
)

pagedView.frame = CGRect(x: 0, y: 0, width: 350, height: 700)

pagedView.pageIndicatorIsInteractive = true

PlaygroundPage.current.liveView = pagedView
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ pod 'SimplePagedView'

## Usage

### Programmatic setup
```swift
// Create a PagedViewController by providing it with a view for each page you'd like it to contain
let pagedViewController = PagedViewController(with:
let simplePagedView = SimplePagedView(with:
LogoView(presenter: welcomePresenter),
CardPageView(image: ThemeManager.Images.welcomeTourSlide1,
subtitle: "Complete and resolve tasks on the go"),
Expand All @@ -24,14 +25,5 @@ let pagedViewController = PagedViewController(with:
subtitle: "Add files and pictures in seconds")
)

// Add the pagedViewController as a child view controller
self.add(pagedViewController) { (childView) -> [NSLayoutConstraint] in
// Return an array of constraints to apply to the paged view
return [
childView.topAnchor.constraint(equalTo: view.readableContentGuide.topAnchor),
childView.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor),
childView.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor),
childView.bottomAnchor.constraint(equalTo: view.readableContentGuide.bottomAnchor)
]
}
// Add as subview and setup constraints/frame
```
16 changes: 4 additions & 12 deletions SimplePagedViewFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
objects = {

/* Begin PBXBuildFile section */
B206EB0D21D69F1E00F39BD3 /* UIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B206EB0C21D69F1E00F39BD3 /* UIView.swift */; };
B2C6870F21C191F2000031AB /* SimplePagedViewFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2C6870521C191F2000031AB /* SimplePagedViewFramework.framework */; };
B2C6871421C191F2000031AB /* SimplePagedViewFrameworkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2C6871321C191F2000031AB /* SimplePagedViewFrameworkTests.swift */; };
B2C6872821C19218000031AB /* NSLayoutConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2C6872021C19217000031AB /* NSLayoutConstraint.swift */; };
B2C6872921C19218000031AB /* UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2C6872121C19217000031AB /* UIImage.swift */; };
B2C6872B21C19218000031AB /* ExternallyInteractiveUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2C6872421C19217000031AB /* ExternallyInteractiveUIView.swift */; };
B2C6872C21C19218000031AB /* SimplePagedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2C6872521C19218000031AB /* SimplePagedView.swift */; };
B2C6873121C1AE10000031AB /* UIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2C6873021C1AE10000031AB /* UIViewController.swift */; };
B2C6898421C342D5000031AB /* PageDotsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2C6898321C342D5000031AB /* PageDotsView.swift */; };
Expand All @@ -37,14 +37,14 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
B206EB0C21D69F1E00F39BD3 /* UIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIView.swift; sourceTree = "<group>"; };
B2C6870521C191F2000031AB /* SimplePagedViewFramework.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SimplePagedViewFramework.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B2C6870921C191F2000031AB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B2C6870E21C191F2000031AB /* SimplePagedViewFrameworkTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SimplePagedViewFrameworkTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
B2C6871321C191F2000031AB /* SimplePagedViewFrameworkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimplePagedViewFrameworkTests.swift; sourceTree = "<group>"; };
B2C6871521C191F2000031AB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B2C6872021C19217000031AB /* NSLayoutConstraint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSLayoutConstraint.swift; sourceTree = "<group>"; };
B2C6872121C19217000031AB /* UIImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImage.swift; sourceTree = "<group>"; };
B2C6872421C19217000031AB /* ExternallyInteractiveUIView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExternallyInteractiveUIView.swift; sourceTree = "<group>"; };
B2C6872521C19218000031AB /* SimplePagedView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimplePagedView.swift; sourceTree = "<group>"; };
B2C6873021C1AE10000031AB /* UIViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewController.swift; sourceTree = "<group>"; };
B2C6898321C342D5000031AB /* PageDotsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageDotsView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -117,25 +117,17 @@
B2C6872021C19217000031AB /* NSLayoutConstraint.swift */,
B2C6872121C19217000031AB /* UIImage.swift */,
B2C6873021C1AE10000031AB /* UIViewController.swift */,
B206EB0C21D69F1E00F39BD3 /* UIView.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
B2C6872321C19217000031AB /* Helpers */ = {
isa = PBXGroup;
children = (
B2C6872421C19217000031AB /* ExternallyInteractiveUIView.swift */,
);
path = Helpers;
sourceTree = "<group>";
};
B2C6872F21C1A8C8000031AB /* Source */ = {
isa = PBXGroup;
children = (
B2C6898521C9805B000031AB /* Errors */,
B2C6872521C19218000031AB /* SimplePagedView.swift */,
B2C6898221C342B6000031AB /* Views */,
B2C6872321C19217000031AB /* Helpers */,
B2C6871F21C19217000031AB /* Extensions */,
);
path = Source;
Expand Down Expand Up @@ -298,11 +290,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B206EB0D21D69F1E00F39BD3 /* UIView.swift in Sources */,
B2C6898721C9806F000031AB /* DotsError.swift in Sources */,
B2C6872821C19218000031AB /* NSLayoutConstraint.swift in Sources */,
B2C689B221CA12E0000031AB /* DotView.swift in Sources */,
B2C6898421C342D5000031AB /* PageDotsView.swift in Sources */,
B2C6872B21C19218000031AB /* ExternallyInteractiveUIView.swift in Sources */,
B2C6872C21C19218000031AB /* SimplePagedView.swift in Sources */,
B2C6872921C19218000031AB /* UIImage.swift in Sources */,
B2C6873121C1AE10000031AB /* UIViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ class ViewController: UIViewController {
with: green, red, orange
)
pagedView.pageIndicatorIsInteractive = true
pagedView.translatesAutoresizingMaskIntoConstraints = false

self.add(pagedView) { (child) -> [NSLayoutConstraint] in
return [
child.topAnchor.constraint(equalTo: view.topAnchor),
child.bottomAnchor.constraint(equalTo: view.bottomAnchor),
child.leadingAnchor.constraint(equalTo: view.leadingAnchor),
child.trailingAnchor.constraint(equalTo: view.trailingAnchor)
]
}
self.view.addSubview(pagedView)

NSLayoutConstraint.activate([
pagedView.topAnchor.constraint(equalTo: view.topAnchor),
pagedView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
pagedView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
pagedView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])
}
}

16 changes: 16 additions & 0 deletions SimplePagedViewFramework/Source/Extensions/UIView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import UIKit

extension UIView {
public func replace<T: UIView>(
subview: UIView,
with other: UIView,
constraints: (_ child: UIView, _ parent: T) -> [NSLayoutConstraint]
) {
let newConstraints = constraints(other, self as! T)
guard let subviewIndex = subview.superview?.subviews.firstIndex(of: subview) else { fatalError() }
subview.removeFromSuperview()
self.insertSubview(other, at: subviewIndex)

NSLayoutConstraint.activate(newConstraints)
}
}

This file was deleted.

Loading

0 comments on commit 92a45db

Please sign in to comment.