Skip to content
This repository was archived by the owner on Nov 2, 2025. It is now read-only.

Commit 62a8dca

Browse files
authored
Merge pull request #11 from cruisediary/development
Development 0.1.1
2 parents 6d6d167 + 51e59e4 commit 62a8dca

9 files changed

Lines changed: 247 additions & 13 deletions

File tree

Example/DeviceLayout.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@
505505
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
506506
PRODUCT_NAME = "$(TARGET_NAME)";
507507
SWIFT_VERSION = 3.0;
508+
TARGETED_DEVICE_FAMILY = "1,2";
508509
};
509510
name = Debug;
510511
};
@@ -520,6 +521,7 @@
520521
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
521522
PRODUCT_NAME = "$(TARGET_NAME)";
522523
SWIFT_VERSION = 3.0;
524+
TARGETED_DEVICE_FAMILY = "1,2";
523525
};
524526
name = Release;
525527
};

Example/DeviceLayout/Base.lproj/LaunchScreen.xib

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<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">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
59
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
10+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
611
</dependencies>
712
<objects>
813
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
@@ -14,17 +19,17 @@
1419
<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">
1520
<rect key="frame" x="20" y="439" width="441" height="21"/>
1621
<fontDescription key="fontDescription" type="system" pointSize="17"/>
17-
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
22+
<color key="textColor" red="0.97254901959999995" green="0.97254901959999995" blue="0.97254901959999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
1823
<nil key="highlightedColor"/>
1924
</label>
2025
<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">
21-
<rect key="frame" x="20" y="140" width="441" height="43"/>
22-
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
23-
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
26+
<rect key="frame" x="20" y="146.5" width="441" height="29"/>
27+
<fontDescription key="fontDescription" name="HelveticaNeue-Bold" family="Helvetica Neue" pointSize="24"/>
28+
<color key="textColor" red="0.97254901959999995" green="0.97254901959999995" blue="0.97254901959999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2429
<nil key="highlightedColor"/>
2530
</label>
2631
</subviews>
27-
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
32+
<color key="backgroundColor" red="0.20000000000000001" green="0.20000000000000001" blue="0.20000000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2833
<constraints>
2934
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
3035
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>

Example/DeviceLayout/Base.lproj/Main.storyboard

Lines changed: 208 additions & 0 deletions
Large diffs are not rendered by default.

Example/Tests/DeviceLayoutConstraintTests.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import XCTest
1010

11+
import Device
1112
import Quick
1213
import Nimble
1314

@@ -39,7 +40,7 @@ class DeviceLayoutConstraintTests: QuickSpec {
3940
describe("DeviceLayoutConstraint") {
4041
context("when use iPhone6") {
4142
beforeEach {
42-
sut.deviceSize = .screen5_5Inch
43+
sut.expectedDeviceSize = .screen5_5Inch
4344
sut.inch5_5 = Expected.Constant.inch5_5
4445
}
4546

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

6162
context("when deviceSize is 4inch device") {
6263
beforeEach {
63-
sut.deviceSize = .screen4Inch
64+
sut.expectedDeviceSize = .screen4Inch
6465
}
6566

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

8687
class DeviceLayoutConstraintSpy: DeviceLayoutConstraint {
88+
var expectedDeviceSize: Size!
8789
var layoutIfNeededCalledCount: Int = 0
90+
8891
override open func layoutIfNeeded() {
8992
layoutIfNeededCalledCount += 1
9093
}
94+
95+
override open func deviceSize() -> Size {
96+
return expectedDeviceSize
97+
}
9198
}

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
# DeviceLayout
22

3+
![logo](README/logo.png)
4+
5+
![Swift](https://img.shields.io/badge/Swift-3.0-orange.svg)
6+
37
[![CI Status](http://img.shields.io/travis/cruisediary/DeviceLayout.svg?style=flat)](https://travis-ci.org/cruisediary/DeviceLayout)
48
[![Version](https://img.shields.io/cocoapods/v/DeviceLayout.svg?style=flat)](http://cocoapods.org/pods/DeviceLayout)
59
[![License](https://img.shields.io/cocoapods/l/DeviceLayout.svg?style=flat)](http://cocoapods.org/pods/DeviceLayout)
610
[![Platform](https://img.shields.io/cocoapods/p/DeviceLayout.svg?style=flat)](http://cocoapods.org/pods/DeviceLayout)
711

12+
**DeviceLayout** is a Swift framework that lets you set *Auto Layout* constraints's differently for each device
13+
814
## Example
915

16+
![logo](README/screenshot1.png)
17+
18+
![logo](README/screenshot2.png)
19+
1020
To run the example project, clone the repo, and run `pod install` from the Example directory first.
1121

1222
## Requirements

README/logo.png

51.2 KB
Loading

README/screenshot1.png

30 KB
Loading

README/screenshot2.png

127 KB
Loading

Sources/DeviceLayoutConstraint.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import Device
1212

1313
class DeviceLayoutConstraint: NSLayoutConstraint {
1414

15-
open var deviceSize: Size = Device.size()
16-
1715
@IBInspectable var inch3_5: CGFloat = 0.0 { didSet { updateConstant(size: .screen3_5Inch, constant: inch3_5)}}
1816
@IBInspectable var inch4: CGFloat = 0.0 { didSet { updateConstant(size: .screen4Inch, constant: inch4)}}
1917
@IBInspectable var inch4_7: CGFloat = 0.0 { didSet { updateConstant(size: .screen4_7Inch, constant: inch4_7)}}
@@ -23,12 +21,16 @@ class DeviceLayoutConstraint: NSLayoutConstraint {
2321
@IBInspectable var inch12_9: CGFloat = 0.0 { didSet { updateConstant(size: .screen12_9Inch, constant: inch12_9)}}
2422

2523
fileprivate func updateConstant(size: Size, constant: CGFloat) {
26-
if size == self.deviceSize {
24+
if size == deviceSize() {
2725
self.constant = constant
2826
layoutIfNeeded()
2927
}
3028
}
3129

30+
open func deviceSize() -> Size {
31+
return Device.size()
32+
}
33+
3234
open func layoutIfNeeded() {
3335
self.firstItem.layoutIfNeeded()
3436
self.secondItem?.layoutIfNeeded()

0 commit comments

Comments
 (0)