Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: define IBDesignable view of ViewController #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions Classes/NorthLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,18 @@ public extension UXView {
}
}
}

public class IBDesignableViewControllerView: UIView {
/// subclasses must override
public func prepareViewControllerForInterfaceBuilder() -> UIViewController { return UIViewController() }

override public func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()

let vc = prepareViewControllerForInterfaceBuilder()
let v = vc.view
v.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
v.frame = bounds
addSubview(v)
}
}
24 changes: 24 additions & 0 deletions Example/NorthLayout-ios/Playground.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="eaK-kE-ze0" customClass="ViewControllerView" customModule="NorthLayout_ios" customModuleProvider="target">
<rect key="frame" x="34" y="56" width="244" height="187"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</objects>
</document>
17 changes: 16 additions & 1 deletion Example/NorthLayout-ios/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,28 @@ private func colorImage(color: UIColor) -> UIImage {
}


@IBDesignable
class ViewControllerView: IBDesignableViewControllerView {
let vc = ViewController()
override func prepareViewControllerForInterfaceBuilder() -> UIViewController {
return vc
}

@IBInspectable var iconColor: UIColor? {
didSet { vc.iconView.image = iconColor.map{colorImage($0)} }
}
}

class ViewController: UIViewController {

let iconView = UIImageView(image: colorImage(UIColor(red: 0.63, green: 0.9, blue: 1, alpha: 1)))

override func loadView() {
super.loadView()

edgesForExtendedLayout = .None
view.backgroundColor = UIColor.whiteColor()

let iconView = UIImageView(image: colorImage(UIColor(red: 0.63, green: 0.9, blue: 1, alpha: 1)))
let iconWidth = CGFloat(32)
iconView.layer.cornerRadius = iconWidth / 2
iconView.clipsToBounds = true
Expand All @@ -39,6 +53,7 @@ class ViewController: UIViewController {
dateLabel.text = "1 min ago"
dateLabel.font = UIFont.systemFontOfSize(12)
dateLabel.textColor = UIColor.lightGrayColor()
dateLabel.setContentHuggingPriority(UILayoutPriorityDefaultHigh, forAxis: .Horizontal)

let textLabel = UILabel()
textLabel.text = "Some text go here"
Expand Down
4 changes: 4 additions & 0 deletions Example/NorthLayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
EA36301D1AFE29520015000C /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EA36301C1AFE29520015000C /* Images.xcassets */; };
EA3630201AFE29520015000C /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = EA36301E1AFE29520015000C /* MainMenu.xib */; };
EA36302C1AFE29520015000C /* NorthLayout_osxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA36302B1AFE29520015000C /* NorthLayout_osxTests.swift */; };
EA9B5C461BCE72CD00CC2103 /* Playground.xib in Resources */ = {isa = PBXBuildFile; fileRef = EA9B5C451BCE72CD00CC2103 /* Playground.xib */; settings = {ASSET_TAGS = (); }; };
EAD9133E1AFE1FDE00F46CB9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD9133D1AFE1FDE00F46CB9 /* AppDelegate.swift */; };
EAD913401AFE1FDE00F46CB9 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD9133F1AFE1FDE00F46CB9 /* ViewController.swift */; };
EAD913451AFE1FDE00F46CB9 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EAD913441AFE1FDE00F46CB9 /* Images.xcassets */; };
Expand Down Expand Up @@ -56,6 +57,7 @@
EA3630251AFE29520015000C /* NorthLayout-osx-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "NorthLayout-osx-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
EA36302A1AFE29520015000C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
EA36302B1AFE29520015000C /* NorthLayout_osxTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NorthLayout_osxTests.swift; sourceTree = "<group>"; };
EA9B5C451BCE72CD00CC2103 /* Playground.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Playground.xib; sourceTree = "<group>"; };
EAD913381AFE1FDE00F46CB9 /* NorthLayout-ios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "NorthLayout-ios.app"; sourceTree = BUILT_PRODUCTS_DIR; };
EAD9133C1AFE1FDE00F46CB9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
EAD9133D1AFE1FDE00F46CB9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -190,6 +192,7 @@
children = (
EAD9133D1AFE1FDE00F46CB9 /* AppDelegate.swift */,
EAD9133F1AFE1FDE00F46CB9 /* ViewController.swift */,
EA9B5C451BCE72CD00CC2103 /* Playground.xib */,
EAD913441AFE1FDE00F46CB9 /* Images.xcassets */,
EAD913461AFE1FDE00F46CB9 /* LaunchScreen.xib */,
EAD9133B1AFE1FDE00F46CB9 /* Supporting Files */,
Expand Down Expand Up @@ -376,6 +379,7 @@
buildActionMask = 2147483647;
files = (
EAD913481AFE1FDE00F46CB9 /* LaunchScreen.xib in Resources */,
EA9B5C461BCE72CD00CC2103 /* Playground.xib in Resources */,
EAD913451AFE1FDE00F46CB9 /* Images.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down