Skip to content

Commit

Permalink
Merge pull request #11 from cruisediary/development
Browse files Browse the repository at this point in the history
Development 0.1.1
  • Loading branch information
cruisediary authored Dec 17, 2016
2 parents 6d6d167 + 51e59e4 commit 62a8dca
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Example/DeviceLayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
Expand All @@ -520,6 +521,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
Expand Down
21 changes: 13 additions & 8 deletions Example/DeviceLayout/Base.lproj/LaunchScreen.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16B2548a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
Expand All @@ -14,17 +19,17 @@
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 CocoaPods. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.97254901959999995" green="0.97254901959999995" blue="0.97254901959999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="DeviceLayout" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="140" width="441" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<rect key="frame" x="20" y="146.5" width="441" height="29"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Bold" family="Helvetica Neue" pointSize="24"/>
<color key="textColor" red="0.97254901959999995" green="0.97254901959999995" blue="0.97254901959999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.20000000000000001" green="0.20000000000000001" blue="0.20000000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
Expand Down
208 changes: 208 additions & 0 deletions Example/DeviceLayout/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions Example/Tests/DeviceLayoutConstraintTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import XCTest

import Device
import Quick
import Nimble

Expand Down Expand Up @@ -39,7 +40,7 @@ class DeviceLayoutConstraintTests: QuickSpec {
describe("DeviceLayoutConstraint") {
context("when use iPhone6") {
beforeEach {
sut.deviceSize = .screen5_5Inch
sut.expectedDeviceSize = .screen5_5Inch
sut.inch5_5 = Expected.Constant.inch5_5
}

Expand All @@ -60,7 +61,7 @@ class DeviceLayoutConstraintTests: QuickSpec {

context("when deviceSize is 4inch device") {
beforeEach {
sut.deviceSize = .screen4Inch
sut.expectedDeviceSize = .screen4Inch
}

context("when set constant per deviceSize") {
Expand All @@ -84,8 +85,14 @@ class DeviceLayoutConstraintTests: QuickSpec {
}

class DeviceLayoutConstraintSpy: DeviceLayoutConstraint {
var expectedDeviceSize: Size!
var layoutIfNeededCalledCount: Int = 0

override open func layoutIfNeeded() {
layoutIfNeededCalledCount += 1
}

override open func deviceSize() -> Size {
return expectedDeviceSize
}
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# DeviceLayout

![logo](README/logo.png)

![Swift](https://img.shields.io/badge/Swift-3.0-orange.svg)

[![CI Status](http://img.shields.io/travis/cruisediary/DeviceLayout.svg?style=flat)](https://travis-ci.org/cruisediary/DeviceLayout)
[![Version](https://img.shields.io/cocoapods/v/DeviceLayout.svg?style=flat)](http://cocoapods.org/pods/DeviceLayout)
[![License](https://img.shields.io/cocoapods/l/DeviceLayout.svg?style=flat)](http://cocoapods.org/pods/DeviceLayout)
[![Platform](https://img.shields.io/cocoapods/p/DeviceLayout.svg?style=flat)](http://cocoapods.org/pods/DeviceLayout)

**DeviceLayout** is a Swift framework that lets you set *Auto Layout* constraints's differently for each device

## Example

![logo](README/screenshot1.png)

![logo](README/screenshot2.png)

To run the example project, clone the repo, and run `pod install` from the Example directory first.

## Requirements
Expand Down
Binary file added README/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added README/screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added README/screenshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions Sources/DeviceLayoutConstraint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import Device

class DeviceLayoutConstraint: NSLayoutConstraint {

open var deviceSize: Size = Device.size()

@IBInspectable var inch3_5: CGFloat = 0.0 { didSet { updateConstant(size: .screen3_5Inch, constant: inch3_5)}}
@IBInspectable var inch4: CGFloat = 0.0 { didSet { updateConstant(size: .screen4Inch, constant: inch4)}}
@IBInspectable var inch4_7: CGFloat = 0.0 { didSet { updateConstant(size: .screen4_7Inch, constant: inch4_7)}}
Expand All @@ -23,12 +21,16 @@ class DeviceLayoutConstraint: NSLayoutConstraint {
@IBInspectable var inch12_9: CGFloat = 0.0 { didSet { updateConstant(size: .screen12_9Inch, constant: inch12_9)}}

fileprivate func updateConstant(size: Size, constant: CGFloat) {
if size == self.deviceSize {
if size == deviceSize() {
self.constant = constant
layoutIfNeeded()
}
}

open func deviceSize() -> Size {
return Device.size()
}

open func layoutIfNeeded() {
self.firstItem.layoutIfNeeded()
self.secondItem?.layoutIfNeeded()
Expand Down

0 comments on commit 62a8dca

Please sign in to comment.