Skip to content

Commit

Permalink
Prepare Demo for webView sgr-ksmt#18
Browse files Browse the repository at this point in the history
  • Loading branch information
sgr-ksmt committed Mar 23, 2016
1 parent 6bbef3e commit 1c87a48
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 4 deletions.
11 changes: 10 additions & 1 deletion Demo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="14F1605" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
Expand Down Expand Up @@ -52,9 +52,18 @@
<action selector="goSampleTableView:" destination="BYZ-38-t0r" eventType="touchUpInside" id="zwK-1N-YJz"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="vuR-cn-rxB">
<rect key="frame" x="243" y="340" width="115" height="30"/>
<state key="normal" title="WebViewSample"/>
<connections>
<action selector="goSampleWebView:" destination="BYZ-38-t0r" eventType="touchUpInside" id="jsT-Zc-itd"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="vuR-cn-rxB" firstAttribute="top" secondItem="8t7-aQ-m9b" secondAttribute="bottom" constant="32" id="Del-tz-jeP"/>
<constraint firstItem="vuR-cn-rxB" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="H14-KM-hNQ"/>
<constraint firstItem="PqT-gX-IbR" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="JPb-m4-YaX"/>
<constraint firstItem="PqT-gX-IbR" firstAttribute="top" secondItem="otR-Ne-HCB" secondAttribute="bottom" constant="32" id="MKa-53-SIW"/>
<constraint firstItem="8t7-aQ-m9b" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="McM-qz-NmT"/>
Expand Down
5 changes: 5 additions & 0 deletions Demo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
6 changes: 3 additions & 3 deletions Demo/SampleTableViewController.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="14F1605" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="4wT-3U-j3F">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="4wT-3U-j3F">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
Expand Down Expand Up @@ -29,7 +29,7 @@
<constraint firstAttribute="width" constant="200" id="yTE-Gm-4vg"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="SYO-87-FkQ">
Expand All @@ -39,7 +39,7 @@
<constraint firstAttribute="height" constant="21" id="Ki8-nY-Zw3"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand Down
7 changes: 7 additions & 0 deletions Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,12 @@ class ViewController: UIViewController {
let vc = storyboard.instantiateInitialViewController() as! SampleTableViewController
presentViewController(vc, animated: true, completion: nil)
}

@objc @IBAction private func goSampleWebView(sender: AnyObject?) {
let storyboard = UIStoryboard(name: "WebViewController", bundle: nil)
let vc = storyboard.instantiateInitialViewController() as! WebViewController
presentViewController(vc, animated: true, completion: nil)
}

}

57 changes: 57 additions & 0 deletions Demo/WebViewController.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="agr-Bd-01h">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
</dependencies>
<scenes>
<!--Web View Controller-->
<scene sceneID="xDk-0N-TTV">
<objects>
<viewController id="agr-Bd-01h" customClass="WebViewController" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="tFx-VQ-KEU"/>
<viewControllerLayoutGuide type="bottom" id="yiC-n7-0o7"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="IRc-XT-O1w">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<webView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VC0-fG-sSg">
<rect key="frame" x="0.0" y="20" width="600" height="200"/>
<color key="backgroundColor" red="0.36078431370000003" green="0.38823529410000002" blue="0.4039215686" alpha="1" colorSpace="deviceRGB"/>
<constraints>
<constraint firstAttribute="height" constant="200" id="BaV-Vk-89A"/>
</constraints>
</webView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="GnF-lf-UMf">
<rect key="frame" x="285" y="250" width="30" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="30" id="fco-gS-WH1"/>
<constraint firstAttribute="height" constant="30" id="tDp-3p-Egp"/>
</constraints>
<state key="normal" title="PDF"/>
<connections>
<action selector="generatePDF" destination="agr-Bd-01h" eventType="touchUpInside" id="1Dr-rA-1tr"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="GnF-lf-UMf" firstAttribute="centerX" secondItem="IRc-XT-O1w" secondAttribute="centerX" id="EEL-dG-gHB"/>
<constraint firstItem="VC0-fG-sSg" firstAttribute="leading" secondItem="IRc-XT-O1w" secondAttribute="leading" id="JFA-ge-bAo"/>
<constraint firstItem="GnF-lf-UMf" firstAttribute="top" secondItem="VC0-fG-sSg" secondAttribute="bottom" constant="30" id="Jxb-tE-jJ6"/>
<constraint firstAttribute="trailing" secondItem="VC0-fG-sSg" secondAttribute="trailing" id="TPP-ws-uqx"/>
<constraint firstItem="VC0-fG-sSg" firstAttribute="top" secondItem="tFx-VQ-KEU" secondAttribute="bottom" id="gls-O5-HeG"/>
</constraints>
</view>
<connections>
<outlet property="webView" destination="VC0-fG-sSg" id="FN0-YH-6N8"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="tD9-QV-HgR" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="762" y="285"/>
</scene>
</scenes>
</document>
56 changes: 56 additions & 0 deletions Demo/WebViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// WebViewController.swift
// PDFGenerator
//
// Created by Suguru Kishimoto on 2016/03/23.
//
//

import UIKit
import WebKit
import PDFGenerator

class WebViewController: UIViewController {

@IBOutlet private weak var webView: UIWebView!

override func viewDidLoad() {
super.viewDidLoad()
let req = NSMutableURLRequest(URL: NSURL(string: "http://www.yahoo.co.jp")!, cachePolicy: .ReloadIgnoringCacheData, timeoutInterval: 60)
webView.loadRequest(req)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

@IBAction func generatePDF() {
do {
let dst = NSHomeDirectory().stringByAppendingString("/sample_tblview.pdf")
try PDFGenerator.generate(webView, outputPath: dst)
openPDFViewer(dst)
} catch let error {
print(error)
}

}

private func openPDFViewer(pdfPath: String) {
let url = NSURL(fileURLWithPath: pdfPath)
let storyboard = UIStoryboard(name: "PDFPreviewVC", bundle: nil)
let vc = storyboard.instantiateInitialViewController() as! PDFPreviewVC
vc.setupWithURL(url)
presentViewController(vc, animated: true, completion: nil)
}

/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/

}
8 changes: 8 additions & 0 deletions PDFGenerator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
4D900B931C8174B8004034C2 /* SampleTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D900B921C8174B8004034C2 /* SampleTableViewController.swift */; };
4D900B951C817582004034C2 /* SampleTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D900B941C817582004034C2 /* SampleTableViewCell.swift */; };
4DC0A7AE1C6C583000E843C8 /* test_image1.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DC0A7AD1C6C583000E843C8 /* test_image1.png */; };
4DF6DEB61CA2590900C97F30 /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF6DEB51CA2590900C97F30 /* WebViewController.swift */; };
4DF6DEB81CA25A5A00C97F30 /* WebViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4DF6DEB71CA25A5A00C97F30 /* WebViewController.storyboard */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -71,6 +73,8 @@
4D900B921C8174B8004034C2 /* SampleTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SampleTableViewController.swift; sourceTree = "<group>"; };
4D900B941C817582004034C2 /* SampleTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SampleTableViewCell.swift; sourceTree = "<group>"; };
4DC0A7AD1C6C583000E843C8 /* test_image1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = test_image1.png; sourceTree = "<group>"; };
4DF6DEB51CA2590900C97F30 /* WebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = "<group>"; };
4DF6DEB71CA25A5A00C97F30 /* WebViewController.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = WebViewController.storyboard; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -150,6 +154,8 @@
4D54FFEB1C65CFFD000A9036 /* PDFPreviewVC.swift */,
4D900B921C8174B8004034C2 /* SampleTableViewController.swift */,
4D900B941C817582004034C2 /* SampleTableViewCell.swift */,
4DF6DEB51CA2590900C97F30 /* WebViewController.swift */,
4DF6DEB71CA25A5A00C97F30 /* WebViewController.storyboard */,
4D900B901C817444004034C2 /* SampleTableViewController.storyboard */,
4D54FFED1C65D008000A9036 /* PDFPreviewVC.storyboard */,
4D4F97B31C6388AA00108BEB /* Main.storyboard */,
Expand Down Expand Up @@ -308,6 +314,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4DF6DEB81CA25A5A00C97F30 /* WebViewController.storyboard in Resources */,
4D4F97D31C639CCB00108BEB /* sample_5.jpg in Resources */,
4D4F97BA1C6388AA00108BEB /* LaunchScreen.storyboard in Resources */,
4D4F97CE1C639CCB00108BEB /* sample_0.jpg in Resources */,
Expand Down Expand Up @@ -348,6 +355,7 @@
buildActionMask = 2147483647;
files = (
4D4F97B21C6388AA00108BEB /* ViewController.swift in Sources */,
4DF6DEB61CA2590900C97F30 /* WebViewController.swift in Sources */,
4D54FFEC1C65CFFD000A9036 /* PDFPreviewVC.swift in Sources */,
4D900B951C817582004034C2 /* SampleTableViewCell.swift in Sources */,
4D4F97B01C6388AA00108BEB /* AppDelegate.swift in Sources */,
Expand Down

0 comments on commit 1c87a48

Please sign in to comment.