Skip to content

Commit e9b5f07

Browse files
author
Kyle Truscott
committed
Creating separate .podspec for swift/framework integration
1 parent d45ab13 commit e9b5f07

8 files changed

+141
-90
lines changed

.gitignore

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
.DS_Store
2-
*.swp
3-
*~.nib
4-
1+
# Xcode
2+
#
53
build/
6-
74
*.pbxuser
8-
*.perspective
5+
!default.pbxuser
6+
*.mode1v3
7+
!default.mode1v3
8+
*.mode2v3
9+
!default.mode2v3
910
*.perspectivev3
10-
11-
Pods
11+
!default.perspectivev3
1212
xcuserdata
13+
*.xccheckout
14+
*.moved-aside
15+
DerivedData
16+
*.hmap
17+
*.ipa
18+
*.xcuserstate
19+
20+
Pods/

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ All notable changes to this project will be documented in this file.
66

77
* Intitial version!
88

9-
## 0.0.2 - 2015-02-26
9+
## 0.0.2 - 2015-03-21
1010

11-
* Swift version!
11+
* Separate swift podspect... thanks @MoridinBG

Example/CenterFlow.xcodeproj/project.pbxproj

+30-18
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
58A0D63F05D348C4BFAF6CBD /* libPods-CenterFlowTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B25D8224D48435FBC3ED5B2 /* libPods-CenterFlowTests.a */; };
11-
A3C7E46C2F984206AB0DE373 /* libPods-CenterFlow.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7EE27BDFC71E4636AB938C3A /* libPods-CenterFlow.a */; };
10+
5351A7ABCC652379D5412043 /* libPods-CenterFlowTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BA0FF2F233AC4708DDDF959F /* libPods-CenterFlowTests.a */; };
11+
89C9C8C1CAA139E8C3F8DC27 /* libPods-CenterFlow.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 19FE6FBDF1A7F0531B0558FC /* libPods-CenterFlow.a */; };
1212
CF2A543419E702E500BAFA7F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = CF2A543319E702E500BAFA7F /* main.m */; };
1313
CF2A543719E702E500BAFA7F /* KTAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = CF2A543619E702E500BAFA7F /* KTAppDelegate.m */; };
1414
CF2A543F19E702E500BAFA7F /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CF2A543E19E702E500BAFA7F /* Images.xcassets */; };
@@ -29,10 +29,12 @@
2929
/* End PBXContainerItemProxy section */
3030

3131
/* Begin PBXFileReference section */
32-
4B25D8224D48435FBC3ED5B2 /* libPods-CenterFlowTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CenterFlowTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
33-
70D6A9920301408DAB9750F2 /* Pods-CenterFlow.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CenterFlow.xcconfig"; path = "Pods/Pods-CenterFlow.xcconfig"; sourceTree = "<group>"; };
34-
7EE27BDFC71E4636AB938C3A /* libPods-CenterFlow.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CenterFlow.a"; sourceTree = BUILT_PRODUCTS_DIR; };
35-
AFF791EDB24B4108AED4EF9C /* Pods-CenterFlowTests.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CenterFlowTests.xcconfig"; path = "Pods/Pods-CenterFlowTests.xcconfig"; sourceTree = "<group>"; };
32+
19FE6FBDF1A7F0531B0558FC /* libPods-CenterFlow.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CenterFlow.a"; sourceTree = BUILT_PRODUCTS_DIR; };
33+
3ECF6DD851140C95357BED1E /* Pods-CenterFlowTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CenterFlowTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CenterFlowTests/Pods-CenterFlowTests.debug.xcconfig"; sourceTree = "<group>"; };
34+
4AFEF64C7155472DB962BE48 /* Pods-CenterFlow.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CenterFlow.release.xcconfig"; path = "Pods/Target Support Files/Pods-CenterFlow/Pods-CenterFlow.release.xcconfig"; sourceTree = "<group>"; };
35+
53AAACBC5E8ACD76A2F4BF31 /* Pods-CenterFlowTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CenterFlowTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-CenterFlowTests/Pods-CenterFlowTests.release.xcconfig"; sourceTree = "<group>"; };
36+
A75292300854AF4BFB32B96E /* Pods-CenterFlow.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CenterFlow.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CenterFlow/Pods-CenterFlow.debug.xcconfig"; sourceTree = "<group>"; };
37+
BA0FF2F233AC4708DDDF959F /* libPods-CenterFlowTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CenterFlowTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
3638
CF2A542E19E702E500BAFA7F /* CenterFlow.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CenterFlow.app; sourceTree = BUILT_PRODUCTS_DIR; };
3739
CF2A543219E702E500BAFA7F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3840
CF2A543319E702E500BAFA7F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
@@ -54,15 +56,15 @@
5456
isa = PBXFrameworksBuildPhase;
5557
buildActionMask = 2147483647;
5658
files = (
57-
A3C7E46C2F984206AB0DE373 /* libPods-CenterFlow.a in Frameworks */,
59+
89C9C8C1CAA139E8C3F8DC27 /* libPods-CenterFlow.a in Frameworks */,
5860
);
5961
runOnlyForDeploymentPostprocessing = 0;
6062
};
6163
CF2A544419E702E500BAFA7F /* Frameworks */ = {
6264
isa = PBXFrameworksBuildPhase;
6365
buildActionMask = 2147483647;
6466
files = (
65-
58A0D63F05D348C4BFAF6CBD /* libPods-CenterFlowTests.a in Frameworks */,
67+
5351A7ABCC652379D5412043 /* libPods-CenterFlowTests.a in Frameworks */,
6668
);
6769
runOnlyForDeploymentPostprocessing = 0;
6870
};
@@ -72,21 +74,31 @@
7274
0405686C57B14B068693DE2D /* Frameworks */ = {
7375
isa = PBXGroup;
7476
children = (
75-
7EE27BDFC71E4636AB938C3A /* libPods-CenterFlow.a */,
76-
4B25D8224D48435FBC3ED5B2 /* libPods-CenterFlowTests.a */,
77+
19FE6FBDF1A7F0531B0558FC /* libPods-CenterFlow.a */,
78+
BA0FF2F233AC4708DDDF959F /* libPods-CenterFlowTests.a */,
7779
);
7880
name = Frameworks;
7981
sourceTree = "<group>";
8082
};
83+
49E6FFD8914783FD091479DC /* Pods */ = {
84+
isa = PBXGroup;
85+
children = (
86+
A75292300854AF4BFB32B96E /* Pods-CenterFlow.debug.xcconfig */,
87+
4AFEF64C7155472DB962BE48 /* Pods-CenterFlow.release.xcconfig */,
88+
3ECF6DD851140C95357BED1E /* Pods-CenterFlowTests.debug.xcconfig */,
89+
53AAACBC5E8ACD76A2F4BF31 /* Pods-CenterFlowTests.release.xcconfig */,
90+
);
91+
name = Pods;
92+
sourceTree = "<group>";
93+
};
8194
CF2A542519E702E500BAFA7F = {
8295
isa = PBXGroup;
8396
children = (
8497
CF2A543019E702E500BAFA7F /* CenterFlow */,
8598
CF2A544A19E702E500BAFA7F /* CenterFlowTests */,
8699
CF2A542F19E702E500BAFA7F /* Products */,
87-
70D6A9920301408DAB9750F2 /* Pods-CenterFlow.xcconfig */,
88100
0405686C57B14B068693DE2D /* Frameworks */,
89-
AFF791EDB24B4108AED4EF9C /* Pods-CenterFlowTests.xcconfig */,
101+
49E6FFD8914783FD091479DC /* Pods */,
90102
);
91103
sourceTree = "<group>";
92104
};
@@ -252,7 +264,7 @@
252264
);
253265
runOnlyForDeploymentPostprocessing = 0;
254266
shellPath = /bin/sh;
255-
shellScript = "\"${SRCROOT}/Pods/Pods-CenterFlowTests-resources.sh\"\n";
267+
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CenterFlowTests/Pods-CenterFlowTests-resources.sh\"\n";
256268
showEnvVarsInLog = 0;
257269
};
258270
6A360096C3484F65AB0C8820 /* Check Pods Manifest.lock */ = {
@@ -282,7 +294,7 @@
282294
);
283295
runOnlyForDeploymentPostprocessing = 0;
284296
shellPath = /bin/sh;
285-
shellScript = "\"${SRCROOT}/Pods/Pods-CenterFlow-resources.sh\"\n";
297+
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CenterFlow/Pods-CenterFlow-resources.sh\"\n";
286298
showEnvVarsInLog = 0;
287299
};
288300
FAB80B0BEE844C7CABCBD919 /* Check Pods Manifest.lock */ = {
@@ -411,7 +423,7 @@
411423
};
412424
CF2A545219E702E500BAFA7F /* Debug */ = {
413425
isa = XCBuildConfiguration;
414-
baseConfigurationReference = 70D6A9920301408DAB9750F2 /* Pods-CenterFlow.xcconfig */;
426+
baseConfigurationReference = A75292300854AF4BFB32B96E /* Pods-CenterFlow.debug.xcconfig */;
415427
buildSettings = {
416428
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
417429
INFOPLIST_FILE = CenterFlow/Info.plist;
@@ -423,7 +435,7 @@
423435
};
424436
CF2A545319E702E500BAFA7F /* Release */ = {
425437
isa = XCBuildConfiguration;
426-
baseConfigurationReference = 70D6A9920301408DAB9750F2 /* Pods-CenterFlow.xcconfig */;
438+
baseConfigurationReference = 4AFEF64C7155472DB962BE48 /* Pods-CenterFlow.release.xcconfig */;
427439
buildSettings = {
428440
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
429441
INFOPLIST_FILE = CenterFlow/Info.plist;
@@ -435,7 +447,7 @@
435447
};
436448
CF2A545519E702E500BAFA7F /* Debug */ = {
437449
isa = XCBuildConfiguration;
438-
baseConfigurationReference = AFF791EDB24B4108AED4EF9C /* Pods-CenterFlowTests.xcconfig */;
450+
baseConfigurationReference = 3ECF6DD851140C95357BED1E /* Pods-CenterFlowTests.debug.xcconfig */;
439451
buildSettings = {
440452
BUNDLE_LOADER = "$(TEST_HOST)";
441453
FRAMEWORK_SEARCH_PATHS = (
@@ -455,7 +467,7 @@
455467
};
456468
CF2A545619E702E500BAFA7F /* Release */ = {
457469
isa = XCBuildConfiguration;
458-
baseConfigurationReference = AFF791EDB24B4108AED4EF9C /* Pods-CenterFlowTests.xcconfig */;
470+
baseConfigurationReference = 53AAACBC5E8ACD76A2F4BF31 /* Pods-CenterFlowTests.release.xcconfig */;
459471
buildSettings = {
460472
BUNDLE_LOADER = "$(TEST_HOST)";
461473
FRAMEWORK_SEARCH_PATHS = (

Example/Podfile.lock

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ EXTERNAL SOURCES:
1212
KTCenterFlowLayout:
1313
:path: ..
1414

15+
CHECKOUT OPTIONS:
16+
KTCategories:
17+
:commit: 383afb30ccab1649dcf9d60c3cd277d6fc42d5f5
18+
:git: https://github.com/keighl/KTCategories.git
19+
1520
SPEC CHECKSUMS:
16-
KTCategories: ab699becac11d8b923aa6750eca2c77006c32d35
17-
KTCenterFlowLayout: dfde4a18640891ef4c4300a8961e9ca7fb6e20b5
21+
KTCategories: bdb65f6f8d1ed9ff67eec33178d4e619d6de7d9d
22+
KTCenterFlowLayout: c120e338e8d064cedbfa865c79012853c45afac5
1823

19-
COCOAPODS: 0.33.1
24+
COCOAPODS: 0.36.0

KTCenterFlowLayout.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
1212
s.platform = :ios, '7.0'
1313
s.requires_arc = true
1414

15-
s.source_files = 'KTCenterFlowLayout.{h,m,swift}’
15+
s.source_files = 'KTCenterFlowLayout.{h,m}'
1616

1717
s.frameworks = 'UIKit'
1818

KTCenterFlowLayout.swift

+56-57
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,72 @@
11
//
22
// KTCenterFlowLayout.swift
3-
// Name It
43
//
54
// Created by Ivan Dilchovski on 2/26/15.
6-
// Copyright (c) 2015 Ivan Dilchovski. All rights reserved.
5+
// Copyright (c) 2014 keighl. All rights reserved.
76
//
87

98
import UIKit
109

1110
class KTCenterFlowLayout: UICollectionViewFlowLayout
1211
{
13-
override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]?
12+
override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]?
13+
{
14+
let superAttributes = super.layoutAttributesForElementsInRect(rect)
15+
var rowCollections = [CGFloat : [UICollectionViewLayoutAttributes]]()
16+
17+
// Collect attributes by their midY coordinate.. i.e. rows!
18+
if let superAttributes = superAttributes
1419
{
15-
let superAttributes = super.layoutAttributesForElementsInRect(rect)
16-
var rowCollections = [CGFloat : [UICollectionViewLayoutAttributes]]()
17-
18-
// Collect attributes by their midY coordinate.. i.e. rows!
19-
if let superAttributes = superAttributes
20+
for attributes in superAttributes as [UICollectionViewLayoutAttributes]
21+
{
22+
let yCenter = CGRectGetMidY(attributes.frame)
23+
if rowCollections[yCenter] == nil
2024
{
21-
for attributes in superAttributes as [UICollectionViewLayoutAttributes]
22-
{
23-
let yCenter = CGRectGetMidY(attributes.frame)
24-
if rowCollections[yCenter] == nil
25-
{
26-
rowCollections[yCenter] = [UICollectionViewLayoutAttributes]()
27-
}
28-
29-
rowCollections[yCenter]!.append(attributes)
30-
}
25+
rowCollections[yCenter] = [UICollectionViewLayoutAttributes]()
3126
}
32-
33-
// Adjust the items in each row
34-
for (key, itemAttributesCollection) in rowCollections
27+
28+
rowCollections[yCenter]!.append(attributes)
29+
}
30+
}
31+
32+
// Adjust the items in each row
33+
for (key, itemAttributesCollection) in rowCollections
34+
{
35+
let itemsInRow = itemAttributesCollection.count
36+
37+
// x-x-x-x ... sum up the interim space
38+
let aggregateInteritemSpacing = self.minimumInteritemSpacing * CGFloat((itemsInRow - 1))
39+
40+
// Sum the width of all elements in the row
41+
var aggregateItemWidths: CGFloat = 0;
42+
for itemAttributes in itemAttributesCollection
43+
{
44+
aggregateItemWidths += CGRectGetWidth(itemAttributes.frame)
45+
}
46+
47+
// Build an alignment rect
48+
// |==|--------|==|
49+
let alignmentWidth = aggregateItemWidths + aggregateInteritemSpacing
50+
let alignmentXOffset = (CGRectGetWidth(rect) - alignmentWidth) / 2
51+
52+
// Adjust each item's position to be centered
53+
var previousFrame = CGRectZero
54+
for itemAttributes in itemAttributesCollection
55+
{
56+
var itemFrame = itemAttributes.frame
57+
if CGRectEqualToRect(previousFrame, CGRectZero)
3558
{
36-
let itemsInRow = itemAttributesCollection.count
37-
38-
// x-x-x-x ... sum up the interim space
39-
let aggregateInteritemSpacing = self.minimumInteritemSpacing * CGFloat((itemsInRow - 1))
40-
41-
// Sum the width of all elements in the row
42-
var aggregateItemWidths: CGFloat = 0;
43-
for itemAttributes in itemAttributesCollection
44-
{
45-
aggregateItemWidths += CGRectGetWidth(itemAttributes.frame)
46-
}
47-
48-
// Build an alignment rect
49-
// |==|--------|==|
50-
let alignmentWidth = aggregateItemWidths + aggregateInteritemSpacing
51-
let alignmentXOffset = (CGRectGetWidth(rect) - alignmentWidth) / 2
52-
53-
// Adjust each item's position to be centered
54-
var previousFrame = CGRectZero
55-
for itemAttributes in itemAttributesCollection
56-
{
57-
var itemFrame = itemAttributes.frame
58-
if CGRectEqualToRect(previousFrame, CGRectZero)
59-
{
60-
itemFrame.origin.x = alignmentXOffset
61-
} else
62-
{
63-
itemFrame.origin.x = CGRectGetMaxX(previousFrame) + self.minimumInteritemSpacing
64-
}
65-
66-
itemAttributes.frame = itemFrame
67-
previousFrame = itemFrame
68-
}
59+
itemFrame.origin.x = alignmentXOffset
60+
} else
61+
{
62+
itemFrame.origin.x = CGRectGetMaxX(previousFrame) + self.minimumInteritemSpacing
63+
}
64+
65+
itemAttributes.frame = itemFrame
66+
previousFrame = itemFrame
6967
}
70-
71-
return superAttributes
68+
}
69+
70+
return superAttributes
7271
}
73-
}
72+
}

KTCenterFlowLayoutSwift.podspec

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Pod::Spec.new do |s|
2+
s.name = "KTCenterFlowLayoutSwift"
3+
s.version = "0.0.1"
4+
s.summary = "Aligns cells to the center of a collection view."
5+
6+
s.homepage = "https://github.com/keighl/KTCenterFlowLayout"
7+
s.license = 'MIT'
8+
s.author = { "keighl" => "keighl@keighl.com" }
9+
s.source = { :git => "https://github.com/keighl/KTCenterFlowLayout.git", :tag => s.version.to_s }
10+
s.social_media_url = 'https://twitter.com/keighl'
11+
12+
s.platform = :ios, '7.0'
13+
s.requires_arc = true
14+
15+
s.source_files = 'KTCenterFlowLayout.{swift}'
16+
17+
s.frameworks = 'UIKit'
18+
19+
end

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,28 @@ KTCenterFlowLayout is a subclass of UICollectionViewFlowLayout which Aligns cell
55
### Usage
66

77
```ruby
8+
// Podfile
9+
810
pod 'KTCenterFlowLayout'
11+
12+
13+
// Using swift?
14+
pod 'KTCenterFlowLayoutSwift'
15+
916
```
1017

1118
Objective-C:
19+
1220
```objective-c
1321
KTCenterFlowLayout *layout = [KTCenterFlowLayout new];
1422
layout.minimumInteritemSpacing = 10.f;
1523
layout.minimumLineSpacing = 10.f;
1624

17-
1825
[[UICollectionViewController alloc] initWithCollectionViewLayout:layout];
1926
```
2027
2128
Swift:
29+
2230
```swift
2331
let layout = KTCenterFlowLayout()
2432
layout.minimumInteritemSpacing = 10.0

0 commit comments

Comments
 (0)