Skip to content

Commit 83030da

Browse files
committed
implement LoadableControl. Also, Happy New Year!
1 parent 5101f38 commit 83030da

File tree

11 files changed

+136
-30
lines changed

11 files changed

+136
-30
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
33

44
# Next
55

6+
* Added `LoadableControl` to allow LoadableView subclasses to have UIControl properties and methods.
7+
68
## [2.2.1](https://github.com/MLSDev/LoadableViews/releases/tag/2.2.1)
79

810
* Updated for Xcode 9.1 / Swift 4.0.2

Example/AppDelegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Example
44
//
55
// Created by Denys Telezhkin on 05.03.16.
6-
// Copyright © 2016 Denys Telezhkin. All rights reserved.
6+
// Copyright © 2018 Denys Telezhkin. All rights reserved.
77
//
88

99
import UIKit
@@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

1616

17-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
17+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1818
// Override point for customization after application launch.
1919
return true
2020
}

Example/Example.storyboard

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<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="Yul-OD-fgm">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Yul-OD-fgm">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
47
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
69
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
10+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
711
</dependencies>
812
<scenes>
913
<!--View Controller-->
@@ -15,29 +19,29 @@
1519
<viewControllerLayoutGuide type="bottom" id="RJa-EI-o4f"/>
1620
</layoutGuides>
1721
<view key="view" contentMode="scaleToFill" id="VOg-Jy-aem">
18-
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
22+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1923
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2024
<subviews>
21-
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="HNX-Ij-lK1" customClass="WTFCatView" customModule="Example" customModuleProvider="target">
22-
<rect key="frame" x="0.0" y="102" width="320" height="276"/>
23-
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
25+
<view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="HNX-Ij-lK1" customClass="WTFCatView" customModule="Example" customModuleProvider="target">
26+
<rect key="frame" x="0.0" y="195.5" width="375" height="276"/>
27+
<color key="backgroundColor" red="0.66666668653488159" green="0.66666668653488159" blue="0.66666668653488159" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2428
<userDefinedRuntimeAttributes>
2529
<userDefinedRuntimeAttribute type="color" keyPath="catBackgroundColor">
26-
<color key="value" red="0.5" green="0.0" blue="0.5" alpha="1" colorSpace="calibratedRGB"/>
30+
<color key="value" red="0.5" green="0.0" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2731
</userDefinedRuntimeAttribute>
2832
</userDefinedRuntimeAttributes>
2933
</view>
3034
</subviews>
31-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
35+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3236
<gestureRecognizers/>
3337
<constraints>
3438
<constraint firstItem="HNX-Ij-lK1" firstAttribute="centerY" secondItem="VOg-Jy-aem" secondAttribute="centerY" id="7UC-fF-zcG"/>
3539
<constraint firstItem="HNX-Ij-lK1" firstAttribute="centerX" secondItem="VOg-Jy-aem" secondAttribute="centerX" id="8O3-Wl-DfO"/>
3640
<constraint firstItem="HNX-Ij-lK1" firstAttribute="leading" secondItem="VOg-Jy-aem" secondAttribute="leading" id="MEb-WZ-BjL"/>
41+
<constraint firstItem="HNX-Ij-lK1" firstAttribute="centerY" secondItem="VOg-Jy-aem" secondAttribute="centerY" id="aQV-CN-Dnw"/>
3742
<constraint firstAttribute="trailing" secondItem="HNX-Ij-lK1" secondAttribute="trailing" id="zsR-rr-Wt8"/>
3843
</constraints>
3944
</view>
40-
<simulatedScreenMetrics key="simulatedDestinationMetrics"/>
4145
</viewController>
4246
<placeholder placeholderIdentifier="IBFirstResponder" id="drI-t0-dfn" userLabel="First Responder" sceneMemberID="firstResponder"/>
4347
</objects>
@@ -52,11 +56,11 @@
5256
<viewControllerLayoutGuide type="bottom" id="8Jg-Nd-p4s"/>
5357
</layoutGuides>
5458
<view key="view" contentMode="scaleToFill" id="qnu-dB-VEx">
55-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
59+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
5660
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
5761
<subviews>
5862
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="1cm-R3-5p2">
59-
<rect key="frame" x="20" y="20" width="560" height="580"/>
63+
<rect key="frame" x="16" y="20" width="343" height="647"/>
6064
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="EVR-vI-g9h">
6165
<size key="itemSize" width="50" height="50"/>
6266
<size key="headerReferenceSize" width="0.0" height="0.0"/>
@@ -70,13 +74,12 @@
7074
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
7175
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
7276
<autoresizingMask key="autoresizingMask"/>
73-
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
7477
</view>
7578
</collectionViewCell>
7679
</cells>
7780
</collectionView>
7881
</subviews>
79-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
82+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
8083
<constraints>
8184
<constraint firstItem="1cm-R3-5p2" firstAttribute="top" secondItem="zyf-hP-NMm" secondAttribute="bottom" id="1Or-2O-1DP"/>
8285
<constraint firstItem="1cm-R3-5p2" firstAttribute="leading" secondItem="qnu-dB-VEx" secondAttribute="leadingMargin" id="J5o-sw-wRq"/>

Example/FooCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// LoadableView
44
//
55
// Created by Denys Telezhkin on 05.03.16.
6-
// Copyright © 2016 Denys Telezhkin. All rights reserved.
6+
// Copyright © 2018 Denys Telezhkin. All rights reserved.
77
//
88

99
import UIKit

Example/WTFCatView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// LoadableView
44
//
55
// Created by Denys Telezhkin on 05.03.16.
6-
// Copyright © 2016 Denys Telezhkin. All rights reserved.
6+
// Copyright © 2018 Denys Telezhkin. All rights reserved.
77
//
88

99
import UIKit

Example/WTFCatView.xib

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
47
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
610
</dependencies>
711
<objects>
812
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
913
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
1014
<view contentMode="scaleToFill" id="iN0-l3-epB">
11-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
15+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1216
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1317
<subviews>
14-
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="wtf_cat" translatesAutoresizingMaskIntoConstraints="NO" id="sCE-9Z-4Tc">
15-
<rect key="frame" x="20" y="20" width="560" height="560"/>
18+
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="wtf_cat" translatesAutoresizingMaskIntoConstraints="NO" id="sCE-9Z-4Tc">
19+
<rect key="frame" x="20" y="20" width="335" height="627"/>
1620
</imageView>
1721
</subviews>
1822
<constraints>
@@ -21,6 +25,7 @@
2125
<constraint firstItem="sCE-9Z-4Tc" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="20" id="r8s-YD-1mw"/>
2226
<constraint firstAttribute="trailing" secondItem="sCE-9Z-4Tc" secondAttribute="trailing" constant="20" id="z3m-zr-43o"/>
2327
</constraints>
28+
<point key="canvasLocation" x="62" y="-13"/>
2429
</view>
2530
</objects>
2631
<resources>

LoadableViews.xcodeproj/project.pbxproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
3E9C31BA1FFFD9A300769D14 /* TextFieldView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E9C31B91FFFD9A300769D14 /* TextFieldView.swift */; };
11+
3E9C31BB1FFFD9AB00769D14 /* TextFieldView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E9C31B91FFFD9A300769D14 /* TextFieldView.swift */; };
12+
3E9C31BD1FFFD9C800769D14 /* TextFieldView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3E9C31BC1FFFD9C800769D14 /* TextFieldView.xib */; };
13+
3E9C31BE1FFFD9D000769D14 /* TextFieldView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3E9C31BC1FFFD9C800769D14 /* TextFieldView.xib */; };
1014
9A148DBD1EDB2924002E610C /* iOSTestableView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9A148DBB1EDB2924002E610C /* iOSTestableView.xib */; };
1115
9A148DBE1EDB2924002E610C /* OverridedView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9A148DBC1EDB2924002E610C /* OverridedView.xib */; };
1216
9A148DC01EDB292A002E610C /* LoadableViewTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A148DBF1EDB292A002E610C /* LoadableViewTestCase.swift */; };
@@ -56,6 +60,8 @@
5660
/* End PBXCopyFilesBuildPhase section */
5761

5862
/* Begin PBXFileReference section */
63+
3E9C31B91FFFD9A300769D14 /* TextFieldView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TextFieldView.swift; path = TestFixtures/TextFieldView.swift; sourceTree = SOURCE_ROOT; };
64+
3E9C31BC1FFFD9C800769D14 /* TextFieldView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = TextFieldView.xib; path = TestFixtures/TextFieldView.xib; sourceTree = SOURCE_ROOT; };
5965
9A148DBB1EDB2924002E610C /* iOSTestableView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = iOSTestableView.xib; path = TestFixtures/iOSTestableView.xib; sourceTree = SOURCE_ROOT; };
6066
9A148DBC1EDB2924002E610C /* OverridedView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = OverridedView.xib; path = TestFixtures/OverridedView.xib; sourceTree = SOURCE_ROOT; };
6167
9A148DBF1EDB292A002E610C /* LoadableViewTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LoadableViewTestCase.swift; path = Tests/LoadableViewsTests/LoadableViewTestCase.swift; sourceTree = SOURCE_ROOT; };
@@ -134,7 +140,7 @@
134140
children = (
135141
9A4BB1D21C8AE989002B1AC9 /* LoadableView.swift */,
136142
);
137-
path = LoadableView;
143+
name = LoadableView;
138144
sourceTree = "<group>";
139145
};
140146
9A4BB1C31C8AE873002B1AC9 /* LoadableViewTests */ = {
@@ -144,7 +150,7 @@
144150
9A148DBC1EDB2924002E610C /* OverridedView.xib */,
145151
9A148DBF1EDB292A002E610C /* LoadableViewTestCase.swift */,
146152
);
147-
path = LoadableViewTests;
153+
name = LoadableViewTests;
148154
sourceTree = "<group>";
149155
};
150156
9A4BB1D11C8AE94A002B1AC9 /* Supporting Files */ = {
@@ -167,6 +173,8 @@
167173
9A6C23851C8B1B190004F507 /* FooCell.xib */,
168174
9A4BB1E21C8B06B4002B1AC9 /* WTFCatView.swift */,
169175
9A4BB20F1C8B076A002B1AC9 /* WTFCatView.xib */,
176+
3E9C31B91FFFD9A300769D14 /* TextFieldView.swift */,
177+
3E9C31BC1FFFD9C800769D14 /* TextFieldView.xib */,
170178
9A4BB1E91C8B06C7002B1AC9 /* AppDelegate.swift */,
171179
9A4BB1F01C8B06C7002B1AC9 /* Assets.xcassets */,
172180
9A4BB1F21C8B06C7002B1AC9 /* LaunchScreen.storyboard */,
@@ -306,6 +314,7 @@
306314
isa = PBXResourcesBuildPhase;
307315
buildActionMask = 2147483647;
308316
files = (
317+
3E9C31BE1FFFD9D000769D14 /* TextFieldView.xib in Resources */,
309318
9A148DBD1EDB2924002E610C /* iOSTestableView.xib in Resources */,
310319
9A148DBE1EDB2924002E610C /* OverridedView.xib in Resources */,
311320
);
@@ -315,6 +324,7 @@
315324
isa = PBXResourcesBuildPhase;
316325
buildActionMask = 2147483647;
317326
files = (
327+
3E9C31BD1FFFD9C800769D14 /* TextFieldView.xib in Resources */,
318328
9A6C23871C8B1B190004F507 /* FooCell.xib in Resources */,
319329
9A4BB1F41C8B06C7002B1AC9 /* LaunchScreen.storyboard in Resources */,
320330
9A4BB2081C8B0726002B1AC9 /* Example.storyboard in Resources */,
@@ -338,6 +348,7 @@
338348
isa = PBXSourcesBuildPhase;
339349
buildActionMask = 2147483647;
340350
files = (
351+
3E9C31BA1FFFD9A300769D14 /* TextFieldView.swift in Sources */,
341352
9A148DC01EDB292A002E610C /* LoadableViewTestCase.swift in Sources */,
342353
);
343354
runOnlyForDeploymentPostprocessing = 0;
@@ -348,6 +359,7 @@
348359
files = (
349360
9A4BB1EA1C8B06C7002B1AC9 /* AppDelegate.swift in Sources */,
350361
9A4BB2111C8B07BE002B1AC9 /* WTFCatView.swift in Sources */,
362+
3E9C31BB1FFFD9AB00769D14 /* TextFieldView.swift in Sources */,
351363
9A6C23861C8B1B190004F507 /* FooCell.swift in Sources */,
352364
);
353365
runOnlyForDeploymentPostprocessing = 0;
@@ -421,7 +433,7 @@
421433
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
422434
GCC_WARN_UNUSED_FUNCTION = YES;
423435
GCC_WARN_UNUSED_VARIABLE = YES;
424-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
436+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
425437
MTL_ENABLE_DEBUG_INFO = YES;
426438
ONLY_ACTIVE_ARCH = YES;
427439
SDKROOT = iphoneos;
@@ -472,7 +484,7 @@
472484
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
473485
GCC_WARN_UNUSED_FUNCTION = YES;
474486
GCC_WARN_UNUSED_VARIABLE = YES;
475-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
487+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
476488
MTL_ENABLE_DEBUG_INFO = NO;
477489
SDKROOT = iphoneos;
478490
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";

Source/LoadableView.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// LoadableView
44
//
55
// Created by Denys Telezhkin on 05.03.16.
6-
// Copyright © 2016 MLSDev Inc(https://mlsdev.com).
6+
// Copyright © 2018 MLSDev Inc(https://mlsdev.com).
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal
@@ -168,3 +168,19 @@ open class LoadableTextField: UITextField, NibLoadableProtocol {
168168
setupView(loadNib(), inContainer: nibContainerView)
169169
}
170170
}
171+
172+
open class LoadableControl: UIControl, NibLoadableProtocol {
173+
override public init(frame: CGRect) {
174+
super.init(frame: frame)
175+
setupNib()
176+
}
177+
178+
required public init?(coder aDecoder: NSCoder) {
179+
super.init(coder: aDecoder)
180+
setupNib()
181+
}
182+
183+
open func setupNib() {
184+
setupView(loadNib(), inContainer: nibContainerView)
185+
}
186+
}

TestFixtures/TextFieldView.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// TextFieldView.swift
3+
// LoadableViewsTests
4+
//
5+
// Created by Denys Telezhkin on 05.01.2018.
6+
// Copyright © 2018 Denys Telezhkin. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import LoadableViews
11+
12+
@IBDesignable class TextFieldView: LoadableControl {
13+
@IBOutlet weak var textField: UITextField!
14+
15+
override func becomeFirstResponder() -> Bool {
16+
return textField.becomeFirstResponder()
17+
}
18+
19+
override func resignFirstResponder() -> Bool {
20+
return textField.resignFirstResponder()
21+
}
22+
}

0 commit comments

Comments
 (0)