Skip to content

Commit

Permalink
Add storyboard support
Browse files Browse the repository at this point in the history
  • Loading branch information
shima11 committed Jun 7, 2017
1 parent 5195a09 commit c16c2a5
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 14 deletions.
6 changes: 0 additions & 6 deletions Demo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

self.window = UIWindow(frame: UIScreen.main.bounds)
let viewController = ViewController()
viewController.view.backgroundColor = UIColor.white
self.window?.rootViewController = viewController
self.window?.makeKeyAndVisible()

return true
}

Expand Down
2 changes: 2 additions & 0 deletions Demo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>ViewController</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
48 changes: 48 additions & 0 deletions Demo/ViewController.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BMs-uN-Yms">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="Wlw-XC-7VO">
<objects>
<viewController id="BMs-uN-Yms" customClass="ViewController" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="CpM-mg-e36"/>
<viewControllerLayoutGuide type="bottom" id="DOo-fa-Lgh"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="F12-d6-zuk">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="pCv-gD-7Lt" customClass="FlexiblePageControl" customModule="Demo" customModuleProvider="target">
<rect key="frame" x="167.5" y="599" width="40" height="20"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="h5I-7U-I7j"/>
<constraint firstAttribute="width" constant="40" id="sbU-l9-mcn"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="DOo-fa-Lgh" firstAttribute="top" secondItem="pCv-gD-7Lt" secondAttribute="bottom" constant="48" id="WoJ-Cx-AjQ"/>
<constraint firstItem="pCv-gD-7Lt" firstAttribute="centerX" secondItem="F12-d6-zuk" secondAttribute="centerX" id="iyL-aM-Ije"/>
</constraints>
</view>
<connections>
<outlet property="pageControl2" destination="pCv-gD-7Lt" id="Dqd-SR-fET"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="D6s-Cc-lwB" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="285.60000000000002" y="311.69415292353824"/>
</scene>
</scenes>
</document>
18 changes: 11 additions & 7 deletions Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class ViewController: UIViewController, UIScrollViewDelegate {
let scrollSize: CGFloat = 300
let numberOfPage: Int = 10

let pageControl = FlexiblePageControl()
let pageControl1 = FlexiblePageControl()

@IBOutlet weak var pageControl2: FlexiblePageControl!

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -25,23 +27,25 @@ class ViewController: UIViewController, UIScrollViewDelegate {
scrollView.contentSize = CGSize(width: scrollSize * CGFloat(numberOfPage), height: scrollSize)
scrollView.isPagingEnabled = true

pageControl.center = CGPoint(x: scrollView.center.x, y: scrollView.frame.maxY + 16)
pageControl.numberOfPages = numberOfPage
pageControl1.center = CGPoint(x: scrollView.center.x, y: scrollView.frame.maxY + 16)
pageControl1.numberOfPages = numberOfPage

pageControl2.numberOfPages = numberOfPage

for index in 0..<numberOfPage {
let view = UIImageView(frame: CGRect(x: CGFloat(index) * scrollSize, y: 0, width: scrollSize, height: scrollSize))
let imageNamed = NSString(format: "image%02d.jpg", index)
view.image = UIImage(named: imageNamed as String)
scrollView.addSubview(view)
}

view.addSubview(scrollView)
view.addSubview(pageControl)
view.addSubview(pageControl1)
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {

pageControl.setProgress(contentOffsetX: scrollView.contentOffset.x, pageWidth: scrollView.bounds.width)
pageControl1.setProgress(contentOffsetX: scrollView.contentOffset.x, pageWidth: scrollView.bounds.width)
pageControl2.setProgress(contentOffsetX: scrollView.contentOffset.x, pageWidth: scrollView.bounds.width)
}

}
4 changes: 4 additions & 0 deletions FlexiblePageControl.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
D42F44971EE7C8FF0097C199 /* ViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D42F44961EE7C8FF0097C199 /* ViewController.storyboard */; };
D44B61A01E98B7AE00D38950 /* image01.jpg in Resources */ = {isa = PBXBuildFile; fileRef = D44B61961E98B7AE00D38950 /* image01.jpg */; };
D44B61A11E98B7AE00D38950 /* image02.jpg in Resources */ = {isa = PBXBuildFile; fileRef = D44B61971E98B7AE00D38950 /* image02.jpg */; };
D44B61A21E98B7AE00D38950 /* image03.jpg in Resources */ = {isa = PBXBuildFile; fileRef = D44B61981E98B7AE00D38950 /* image03.jpg */; };
Expand All @@ -27,6 +28,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
D42F44961EE7C8FF0097C199 /* ViewController.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = ViewController.storyboard; sourceTree = "<group>"; };
D44B61961E98B7AE00D38950 /* image01.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = image01.jpg; path = resouce/image01.jpg; sourceTree = "<group>"; };
D44B61971E98B7AE00D38950 /* image02.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = image02.jpg; path = resouce/image02.jpg; sourceTree = "<group>"; };
D44B61981E98B7AE00D38950 /* image03.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = image03.jpg; path = resouce/image03.jpg; sourceTree = "<group>"; };
Expand Down Expand Up @@ -117,6 +119,7 @@
children = (
D4DC6C4C1E92B9310022F452 /* AppDelegate.swift */,
D4DC6C4E1E92B9310022F452 /* ViewController.swift */,
D42F44961EE7C8FF0097C199 /* ViewController.storyboard */,
D4DC6C531E92B9310022F452 /* Assets.xcassets */,
D4DC6C551E92B9310022F452 /* LaunchScreen.storyboard */,
D4DC6C581E92B9310022F452 /* Info.plist */,
Expand Down Expand Up @@ -231,6 +234,7 @@
D4DC6C541E92B9310022F452 /* Assets.xcassets in Resources */,
D44B61A21E98B7AE00D38950 /* image03.jpg in Resources */,
D44B61A51E98B7AE00D38950 /* image06.jpg in Resources */,
D42F44971EE7C8FF0097C199 /* ViewController.storyboard in Resources */,
D44B61A01E98B7AE00D38950 /* image01.jpg in Resources */,
D44B61AB1E98B9C300D38950 /* image00.jpg in Resources */,
D44B61A61E98B7AE00D38950 /* image07.jpg in Resources */,
Expand Down
6 changes: 5 additions & 1 deletion FlexiblePageControl/FlexiblePageControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ public class FlexiblePageControl: UIView {
}

required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")

super.init(coder: aDecoder)

setup()
updateViewSize()
}

public override func layoutSubviews() {
Expand Down

0 comments on commit c16c2a5

Please sign in to comment.