Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions AnotherStoryboard.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6250" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
</dependencies>
<scenes>
<!--Page View Controller Page-->
<scene sceneID="rzV-S0-pfd">
<objects>
<viewController storyboardIdentifier="page5" id="WOV-HG-qhc" customClass="MSPageViewControllerPage" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="5E2-Yb-ptR"/>
<viewControllerLayoutGuide type="bottom" id="Lxm-8e-zz7"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="3wL-ub-8xC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="View from different storyboard" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Cuz-JL-bAU">
<rect key="frame" x="185" y="59" width="231" height="21"/>
<constraints>
<constraint firstAttribute="width" constant="231" id="pam-RW-MkC"/>
<constraint firstAttribute="height" constant="21" id="z9u-nL-k4q"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="Cuz-JL-bAU" firstAttribute="top" secondItem="5E2-Yb-ptR" secondAttribute="bottom" constant="39" id="TKA-e0-amw"/>
<constraint firstAttribute="centerX" secondItem="Cuz-JL-bAU" secondAttribute="centerX" id="wuo-ai-TjL"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="D1c-1p-RfJ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="358" y="423"/>
</scene>
</scenes>
</document>
4 changes: 4 additions & 0 deletions MSPageViewController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
57EFFA8A18B159B5002E5577 /* MSPageViewControllerPage.m in Sources */ = {isa = PBXBuildFile; fileRef = 57EFFA8918B159B5002E5577 /* MSPageViewControllerPage.m */; };
57EFFA8E18B15AC6002E5577 /* MSPageViewControllerExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 57EFFA8D18B15AC6002E5577 /* MSPageViewControllerExample.m */; };
57EFFA9018B15AD9002E5577 /* MSPageViewControllerExample.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 57EFFA8F18B15AD9002E5577 /* MSPageViewControllerExample.storyboard */; };
653D9C051A22362E00DCE4F5 /* AnotherStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 653D9C041A22362E00DCE4F5 /* AnotherStoryboard.storyboard */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -60,6 +61,7 @@
57EFFA8C18B15AC6002E5577 /* MSPageViewControllerExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MSPageViewControllerExample.h; path = Example/MSPageViewControllerExample.h; sourceTree = "<group>"; };
57EFFA8D18B15AC6002E5577 /* MSPageViewControllerExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MSPageViewControllerExample.m; path = Example/MSPageViewControllerExample.m; sourceTree = "<group>"; };
57EFFA8F18B15AD9002E5577 /* MSPageViewControllerExample.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = MSPageViewControllerExample.storyboard; path = Example/MSPageViewControllerExample.storyboard; sourceTree = "<group>"; };
653D9C041A22362E00DCE4F5 /* AnotherStoryboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = AnotherStoryboard.storyboard; path = ../AnotherStoryboard.storyboard; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -176,6 +178,7 @@
57EFFA8C18B15AC6002E5577 /* MSPageViewControllerExample.h */,
57EFFA8D18B15AC6002E5577 /* MSPageViewControllerExample.m */,
57EFFA8F18B15AD9002E5577 /* MSPageViewControllerExample.storyboard */,
653D9C041A22362E00DCE4F5 /* AnotherStoryboard.storyboard */,
);
name = Example;
sourceTree = "<group>";
Expand Down Expand Up @@ -257,6 +260,7 @@
buildActionMask = 2147483647;
files = (
57EFFA9018B15AD9002E5577 /* MSPageViewControllerExample.storyboard in Resources */,
653D9C051A22362E00DCE4F5 /* AnotherStoryboard.storyboard in Resources */,
57EFFA5C18B149F7002E5577 /* InfoPlist.strings in Resources */,
57EFFA6418B149F7002E5577 /* Images.xcassets in Resources */,
);
Expand Down
2 changes: 1 addition & 1 deletion MSPageViewController/Example/MSPageViewControllerExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ + (void)initialize {
}

- (NSArray *)pageIdentifiers {
return @[@"page1", @"page2", @"page3", @"page4"];
return @[@"page1", @"page2", @"page3", @"page4", @"AnotherStoryboard:page5"];
}

@end
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="aNA-kg-caK">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6250" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="aNA-kg-caK">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3747"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
</dependencies>
<scenes>
<!--Page 1-->
Expand All @@ -18,7 +19,6 @@
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="This is page 1" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Bac-mN-dim">
<rect key="frame" x="107" y="274" width="107" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -49,7 +49,6 @@
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="This is page 2" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="l3L-OV-ZgU">
<rect key="frame" x="107" y="274" width="107" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -80,7 +79,6 @@
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="This is page 3" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lQD-yy-bRk">
<rect key="frame" x="107" y="274" width="107" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -111,7 +109,6 @@
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="This is page 4" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hhP-Un-bck">
<rect key="frame" x="107" y="274" width="107" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -142,4 +139,4 @@
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
}
],
"info" : {
Expand Down
13 changes: 13 additions & 0 deletions MSPageViewController/Source/MSPageViewController+Protected.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,17 @@
*/
- (UIViewController *)viewControllerAtIndex:(NSInteger)index;

/**
* @note Can be overridden.
* @discussion Storyboard factory. May be overriden to provide TyphoonStoryboard instance
*/
- (UIStoryboard *)storyboardWithName:(NSString *)name index:(NSInteger) storyboardIndex;

/**
* @note Can be overridden.
* @discussion Controller factory.
*/

- (UIViewController *)instantiateViewControllerWithIdentifier:(NSString*)identifier storyboard:(UIStoryboard*) fromStoryboard;

@end
31 changes: 30 additions & 1 deletion MSPageViewController/Source/MSPageViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ - (void)setUpViewController:(UIViewController<MSPageViewControllerChild> *)viewC

}

- (UIStoryboard *)storyboardWithName:(NSString *)name index:(NSInteger) storyboardIndex {
return [UIStoryboard storyboardWithName: name bundle: nil];
}

- (UIViewController *)instantiateViewControllerWithIdentifier:(NSString*)identifier storyboard:(UIStoryboard*) fromStoryboard {
return [fromStoryboard instantiateViewControllerWithIdentifier:identifier];
}

#pragma mark -

- (void)viewDidLoad {
Expand Down Expand Up @@ -92,7 +100,7 @@ - (UIViewController *)viewControllerAtIndex:(NSInteger)index {
NSAssert(self.storyboard,
@"This controller is only meant to be used inside of a UIStoryboard");

result = [self.storyboard instantiateViewControllerWithIdentifier:self.pageIdentifiers[(NSUInteger)index]];
result = [self instantiateViewController: self.pageIdentifiers[(NSUInteger)index] withIndex:index];

NSParameterAssert(result);
NSAssert([result conformsToProtocol:@protocol(MSPageViewControllerChild)],
Expand All @@ -119,4 +127,25 @@ - (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)page
return [pageViewController.viewControllers.lastObject pageIndex];
}

#pragma mark ViewController instantiation
-(UIViewController<MSPageViewControllerChild> *)instantiateViewController:(NSString*)identifier withIndex: (NSInteger) index {
UIViewController<MSPageViewControllerChild> *result = nil;

UIStoryboard* storyboard = self.storyboard;

NSArray* storyboardAndIdentifier = [identifier componentsSeparatedByString: @":"];

if (storyboardAndIdentifier.count == 2) {
storyboard = [self storyboardWithName: storyboardAndIdentifier[0] index: index];
identifier = storyboardAndIdentifier[1];
NSAssert(storyboard, @"Unable to find specified Storyboard by name");
NSAssert([identifier length] > 0, @"Specified identified should not be empty");
}
result = (UIViewController<MSPageViewControllerChild>*)[self instantiateViewControllerWithIdentifier:identifier storyboard: storyboard];

NSParameterAssert(result);
return result;
}


@end
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ With ```MSPageViewController``` you will be able to design each page from a sing
First you must create a [subclass of ```MSPageViewController```](MSPageViewController/Source/MSPageViewController+Protected.h) and override ```-pageIdentifiers```. Example:
```objc
- (NSArray *)pageIdentifiers {
return @[@"page1", @"page2"];
return @[@"page1", @"page2", @"AnotherStoryboard:page3"];
}
```

Then you have to create a storyboard, add a ```UIPageViewController``` object and change its class to ```MSPageViewController```.
Then you can add the controllers, setting their ```Storyboard ID```s to what you returned in ```pageIdentifiers```.
Each of them must be a class that conforms to ```MSPageViewControllerChild``` (if you don't need to add any extra functionality to it you can use [```MSPageViewControllerPage```](MSPageViewController/Source/MSPageViewControllerPage.h)).

You might specify Storyboard name using colon
```
StoryBoardName:pageIdentifier
```
Also, you can specify bunlde. In order to do that you have to override ```- (NSBundle*)storyboardBundleForIndex:(NSInteger)index```

When your controller is instantiated, it will use these controllers to create each page.

Make sure you also check out the sample project in this repo.
Expand Down