Skip to content

Commit bffe9ab

Browse files
authored
Merge pull request #13 from touchlane/develop
Release 0.0.7
2 parents 9eee933 + e5f137e commit bffe9ab

File tree

14 files changed

+285
-18
lines changed

14 files changed

+285
-18
lines changed

.swift-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# Changelog for CampcotCollectionView 0.0.7
2+
### Fixed
3+
* Fixed crash with storyboard implementation.
4+
5+
### Added
6+
* Storyboard support.
7+
* Properties in `Attributes Inspector` for `CampcotCollectionView`.
8+
* Example for storyboard implementation.
9+
110
# Changelog for CampcotCollectionView 0.0.6
211
### Added
312
* `contentSizeAdjustmentBehavior` property allows to manage content size calculation.

CampcotCollectionView.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'CampcotCollectionView'
3-
s.version = '0.0.6'
3+
s.version = '0.0.7'
44
s.summary = 'CapmcotCollectionView is custom UICollectionView that allows to expand and collapse sections.'
55
s.description = 'This library provides a custom UICollectionView that allows to expand and collapse sections.' \
66
'It provides a simple API to manage collection view appearance.'
@@ -10,4 +10,5 @@ Pod::Spec.new do |s|
1010
s.source = { :git => 'https://github.com/touchlane/CampcotCollectionView.git', :tag => s.version.to_s }
1111
s.ios.deployment_target = '9.0'
1212
s.source_files = 'Source/*.swift'
13+
s.swift_versions = ['5.0']
1314
end

CampcotCollectionView.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
DD35D949201B5E280049ED03 /* ExpandedLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpandedLayout.swift; sourceTree = "<group>"; };
4040
DD35D987201B66B40049ED03 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
4141
DD35D988201B66B40049ED03 /* CampcotCollectionView.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CampcotCollectionView.podspec; sourceTree = "<group>"; };
42-
DD35D989201B66B40049ED03 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
42+
DD35D989201B66B40049ED03 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; tabWidth = 3; };
4343
DDC6199E2369C68100B6981E /* ContentSizeAdjustmentBehavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentSizeAdjustmentBehavior.swift; sourceTree = "<group>"; };
4444
DDFB5C7F201F451E00F8E164 /* CollapsedLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollapsedLayout.swift; sourceTree = "<group>"; };
4545
DDFB5C81201F522B00F8E164 /* CampcotCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CampcotCollectionView.swift; sourceTree = "<group>"; };

Example/Example.xcodeproj/project.pbxproj

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

99
/* Begin PBXBuildFile section */
1010
86EB284F203DE4920052BFA2 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 86EB284D203DE4920052BFA2 /* Launch Screen.storyboard */; };
11+
A3B228A923ED503D00757A28 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A3B228A823ED503D00757A28 /* Main.storyboard */; };
12+
A3B228AC23ED525100757A28 /* StoryboardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3B228AB23ED525100757A28 /* StoryboardViewController.swift */; };
1113
DD35D958201B5F390049ED03 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD35D957201B5F390049ED03 /* AppDelegate.swift */; };
1214
DD35D95A201B5F390049ED03 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD35D959201B5F390049ED03 /* ViewController.swift */; };
1315
DD35D95F201B5F390049ED03 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DD35D95E201B5F390049ED03 /* Images.xcassets */; };
@@ -56,6 +58,8 @@
5658

5759
/* Begin PBXFileReference section */
5860
86EB284D203DE4920052BFA2 /* Launch Screen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
61+
A3B228A823ED503D00757A28 /* Main.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
62+
A3B228AB23ED525100757A28 /* StoryboardViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryboardViewController.swift; sourceTree = "<group>"; };
5963
DD35D954201B5F390049ED03 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
6064
DD35D957201B5F390049ED03 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
6165
DD35D959201B5F390049ED03 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
@@ -98,11 +102,13 @@
98102
isa = PBXGroup;
99103
children = (
100104
DD35D959201B5F390049ED03 /* ViewController.swift */,
105+
A3B228AB23ED525100757A28 /* StoryboardViewController.swift */,
101106
DD35D97E201B63F70049ED03 /* CustomHeaderView.swift */,
102107
DD35D97F201B63F70049ED03 /* CustomCollectionViewCell.swift */,
103108
DD35D957201B5F390049ED03 /* AppDelegate.swift */,
104109
DD35D95E201B5F390049ED03 /* Images.xcassets */,
105110
86EB284D203DE4920052BFA2 /* Launch Screen.storyboard */,
111+
A3B228A823ED503D00757A28 /* Main.storyboard */,
106112
DD35D969201B5FB10049ED03 /* Supporting Files */,
107113
);
108114
path = Source;
@@ -212,6 +218,7 @@
212218
files = (
213219
86EB284F203DE4920052BFA2 /* Launch Screen.storyboard in Resources */,
214220
DD35D95F201B5F390049ED03 /* Images.xcassets in Resources */,
221+
A3B228A923ED503D00757A28 /* Main.storyboard in Resources */,
215222
);
216223
runOnlyForDeploymentPostprocessing = 0;
217224
};
@@ -222,6 +229,7 @@
222229
isa = PBXSourcesBuildPhase;
223230
buildActionMask = 2147483647;
224231
files = (
232+
A3B228AC23ED525100757A28 /* StoryboardViewController.swift in Sources */,
225233
DD35D95A201B5F390049ED03 /* ViewController.swift in Sources */,
226234
DD35D981201B63F70049ED03 /* CustomCollectionViewCell.swift in Sources */,
227235
DD35D980201B63F70049ED03 /* CustomHeaderView.swift in Sources */,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Example/Source/CustomCollectionViewCell.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ class CustomCollectionViewCell: UICollectionViewCell {
2222

2323
override init(frame: CGRect) {
2424
super.init(frame: .zero)
25+
self.commonInit()
26+
}
27+
28+
required init?(coder aDecoder: NSCoder) {
29+
super.init(coder: aDecoder)
30+
self.commonInit()
31+
}
32+
33+
private func commonInit() {
2534
self.clipsToBounds = true
2635
self.backgroundColor = self.internalBackgroundColor
2736
self.layer.cornerRadius = 10
@@ -32,10 +41,6 @@ class CustomCollectionViewCell: UICollectionViewCell {
3241
self.activateTextLabelConstraints(view: self.textLabel, anchorView: self)
3342
}
3443

35-
required init?(coder aDecoder: NSCoder) {
36-
fatalError("init(coder:) has not been implemented")
37-
}
38-
3944
override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
4045
super.apply(layoutAttributes)
4146
self.layoutIfNeeded()

Example/Source/CustomHeaderView.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ class CustomHeaderView: UICollectionReusableView {
2828

2929
override init(frame: CGRect) {
3030
super.init(frame: .zero)
31+
self.commonInit()
32+
}
33+
34+
required init?(coder aDecoder: NSCoder) {
35+
super.init(coder: aDecoder)
36+
self.commonInit()
37+
}
38+
39+
private func commonInit() {
3140
self.backgroundColor = self.internalBackgroundColor
3241
self.textLabel.translatesAutoresizingMaskIntoConstraints = false
3342
self.textLabel.textColor = .white
@@ -39,10 +48,6 @@ class CustomHeaderView: UICollectionReusableView {
3948
self.addGestureRecognizer(tapRecognizer)
4049
}
4150

42-
required init?(coder aDecoder: NSCoder) {
43-
fatalError("init(coder:) has not been implemented")
44-
}
45-
4651
override func prepareForReuse() {
4752
super.prepareForReuse()
4853
self.text = nil

Example/Source/Main.storyboard

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="50H-WV-jbO">
3+
<device id="retina6_1" orientation="portrait" appearance="light"/>
4+
<dependencies>
5+
<deployment identifier="iOS"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
7+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
8+
<capability name="collection view cell content view" minToolsVersion="11.0"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10+
</dependencies>
11+
<scenes>
12+
<!--Storyboard View Controller-->
13+
<scene sceneID="Bn2-4k-qfx">
14+
<objects>
15+
<viewController storyboardIdentifier="viewController" id="50H-WV-jbO" customClass="StoryboardViewController" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
16+
<view key="view" contentMode="scaleToFill" id="p7o-vJ-Y8e">
17+
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
18+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<subviews>
20+
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="CiI-U7-IGk" customClass="CampcotCollectionView" customModule="CampcotCollectionView">
21+
<rect key="frame" x="0.0" y="44" width="414" height="818"/>
22+
<color key="backgroundColor" red="0.74117647058823533" green="0.76470588235294112" blue="0.7803921568627451" alpha="1" colorSpace="calibratedRGB"/>
23+
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="n55-JI-Luz">
24+
<size key="itemSize" width="72" height="72"/>
25+
<size key="headerReferenceSize" width="50" height="50"/>
26+
<size key="footerReferenceSize" width="0.0" height="0.0"/>
27+
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
28+
</collectionViewFlowLayout>
29+
<cells>
30+
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" reuseIdentifier="CustomCell" id="B6o-dS-0wb" customClass="CustomCollectionViewCell" customModule="Example" customModuleProvider="target">
31+
<rect key="frame" x="0.0" y="50" width="72" height="72"/>
32+
<autoresizingMask key="autoresizingMask"/>
33+
<collectionViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="mMo-R2-YRQ">
34+
<rect key="frame" x="0.0" y="0.0" width="72" height="72"/>
35+
<autoresizingMask key="autoresizingMask"/>
36+
</collectionViewCellContentView>
37+
<size key="customSize" width="72" height="72"/>
38+
</collectionViewCell>
39+
</cells>
40+
<collectionReusableView key="sectionHeaderView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" reuseIdentifier="CustomHeaderView" id="Zbe-JP-2ZF" customClass="CustomHeaderView" customModule="Example" customModuleProvider="target">
41+
<rect key="frame" x="0.0" y="0.0" width="414" height="50"/>
42+
<autoresizingMask key="autoresizingMask"/>
43+
</collectionReusableView>
44+
<userDefinedRuntimeAttributes>
45+
<userDefinedRuntimeAttribute type="number" keyPath="top">
46+
<real key="value" value="0.0"/>
47+
</userDefinedRuntimeAttribute>
48+
<userDefinedRuntimeAttribute type="number" keyPath="topInset">
49+
<real key="value" value="10"/>
50+
</userDefinedRuntimeAttribute>
51+
<userDefinedRuntimeAttribute type="number" keyPath="bottomInset">
52+
<real key="value" value="10"/>
53+
</userDefinedRuntimeAttribute>
54+
<userDefinedRuntimeAttribute type="number" keyPath="leftInset">
55+
<real key="value" value="10"/>
56+
</userDefinedRuntimeAttribute>
57+
<userDefinedRuntimeAttribute type="number" keyPath="rightInset">
58+
<real key="value" value="10"/>
59+
</userDefinedRuntimeAttribute>
60+
<userDefinedRuntimeAttribute type="boolean" keyPath="sectionHeadersPinToVisibleBounds" value="YES"/>
61+
<userDefinedRuntimeAttribute type="number" keyPath="minimumSectionSpacing">
62+
<real key="value" value="1"/>
63+
</userDefinedRuntimeAttribute>
64+
<userDefinedRuntimeAttribute type="number" keyPath="minimumInteritemSpacing">
65+
<real key="value" value="10"/>
66+
</userDefinedRuntimeAttribute>
67+
<userDefinedRuntimeAttribute type="number" keyPath="minimumLineSpacing">
68+
<real key="value" value="10"/>
69+
</userDefinedRuntimeAttribute>
70+
</userDefinedRuntimeAttributes>
71+
<connections>
72+
<outlet property="dataSource" destination="50H-WV-jbO" id="u27-tO-IDt"/>
73+
<outlet property="delegate" destination="50H-WV-jbO" id="x0f-La-Hkc"/>
74+
</connections>
75+
</collectionView>
76+
</subviews>
77+
<color key="backgroundColor" red="0.74117647060000003" green="0.76470588240000004" blue="0.78039215689999997" alpha="1" colorSpace="calibratedRGB"/>
78+
<constraints>
79+
<constraint firstItem="03S-Zr-mha" firstAttribute="bottom" secondItem="CiI-U7-IGk" secondAttribute="bottom" id="TNE-uS-6yy"/>
80+
<constraint firstItem="03S-Zr-mha" firstAttribute="trailing" secondItem="CiI-U7-IGk" secondAttribute="trailing" id="UyL-lV-7Ce"/>
81+
<constraint firstItem="CiI-U7-IGk" firstAttribute="leading" secondItem="03S-Zr-mha" secondAttribute="leading" id="ZWJ-fV-Esm"/>
82+
<constraint firstItem="CiI-U7-IGk" firstAttribute="top" secondItem="03S-Zr-mha" secondAttribute="top" id="aNo-19-2P1"/>
83+
</constraints>
84+
<viewLayoutGuide key="safeArea" id="03S-Zr-mha"/>
85+
</view>
86+
<connections>
87+
<outlet property="collectionView" destination="CiI-U7-IGk" id="jdf-Vd-Nl0"/>
88+
</connections>
89+
</viewController>
90+
<placeholder placeholderIdentifier="IBFirstResponder" id="Tcc-yi-6ep" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
91+
</objects>
92+
<point key="canvasLocation" x="-339.13043478260875" y="49.553571428571423"/>
93+
</scene>
94+
</scenes>
95+
</document>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//
2+
// StoryboardViewController.swift
3+
// Example
4+
//
5+
// Created by Alex Yanski on 2/7/20.
6+
// Copyright © 2020 Touchlane LLC. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import CampcotCollectionView
11+
12+
class StoryboardViewController: UIViewController {
13+
14+
@IBOutlet weak var collectionView: CampcotCollectionView!
15+
16+
let itemsInRow = 2
17+
var itemsInSection: [Int: Int] = [:]
18+
19+
override var preferredStatusBarStyle: UIStatusBarStyle {
20+
return .default
21+
}
22+
}
23+
24+
extension StoryboardViewController: UICollectionViewDataSource {
25+
func numberOfSections(in collectionView: UICollectionView) -> Int {
26+
return 20
27+
}
28+
29+
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
30+
if let numberOfItems = itemsInSection[section] {
31+
return numberOfItems
32+
}
33+
let numberOfItems = Int.random(in: 1...6)
34+
itemsInSection[section] = numberOfItems
35+
return numberOfItems
36+
}
37+
38+
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
39+
let cell = collectionView.dequeueReusableCell(
40+
withReuseIdentifier: CustomCollectionViewCell.reuseIdentifier,
41+
for: indexPath) as! CustomCollectionViewCell
42+
cell.text = "\(indexPath.section):\(indexPath.row)"
43+
return cell
44+
}
45+
46+
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
47+
let view = collectionView.dequeueReusableSupplementaryView(
48+
ofKind: kind,
49+
withReuseIdentifier: CustomHeaderView.reuseIdentifier,
50+
for: indexPath) as! CustomHeaderView
51+
view.section = indexPath.section
52+
view.text = "section: \(indexPath.section)"
53+
view.delegate = self
54+
return view
55+
}
56+
}
57+
58+
extension StoryboardViewController: UICollectionViewDelegateFlowLayout {
59+
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
60+
let interitemSpacing = self.collectionView.minimumInteritemSpacing * CGFloat(itemsInRow - 1)
61+
let totalSpacing = collectionView.bounds.width - self.collectionView.sectionInset.left - self.collectionView.sectionInset.right - interitemSpacing
62+
let width = totalSpacing / CGFloat(itemsInRow)
63+
return CGSize(width: width, height: width)
64+
}
65+
66+
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
67+
return CGSize(width: UIScreen.main.bounds.size.width, height: 60)
68+
}
69+
}
70+
71+
extension StoryboardViewController: CustomHeaderViewDelegate {
72+
func selectSection(section: Int) {
73+
self.collectionView.toggle(to: section, animated: true)
74+
}
75+
}

0 commit comments

Comments
 (0)