Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0
12 changes: 12 additions & 0 deletions PinterestLayout.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Pod::Spec.new do |s|
s.name = "PinterestLayout"
s.version = "1.0.0"
s.summary = "Pinterest like layout."
s.homepage = "https://github.com/romansorochak"
s.license = "MIT"
s.author = { "Roman Sorochak" => "roman.sorochak@gmail.com" }
s.platform = :ios, "8.0"
s.ios.deployment_target = "8.0"
s.source = { :git => "https://github.com/MagicLab-team/PinterestLayout.git", :tag => s.version }
s.source_files = "PinterestLayout/*.swift"
end
94 changes: 82 additions & 12 deletions PinterestLayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@
objects = {

/* Begin PBXBuildFile section */
640095F71F0BC37F006AE391 /* CollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640095F61F0BC37F006AE391 /* CollectionViewCell.swift */; };
644F27AA1F0BF039004AD5AD /* RoundedCornersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 644F27A91F0BF039004AD5AD /* RoundedCornersView.swift */; };
B572E5EF1F0C20D100540F7C /* PinterestHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = B572E5EE1F0C20D100540F7C /* PinterestHeader.swift */; };
B5A3F3611F0FDFD3008E44BF /* CustomCollectionVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A3F3601F0FDFD3008E44BF /* CustomCollectionVC.swift */; };
B5A3F3631F0FE119008E44BF /* PinterestVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A3F3621F0FE119008E44BF /* PinterestVC.swift */; };
B5A3F3641F0FE1C2008E44BF /* PinterestLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CF9EF21F0BB1D200DAA3B7 /* PinterestLayout.swift */; };
B5A3F3651F0FE1D1008E44BF /* PinterestCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 646640331F0F99470076207D /* PinterestCell.swift */; };
B5A3F3661F0FE1D4008E44BF /* Help.swift in Sources */ = {isa = PBXBuildFile; fileRef = 646640371F0FD05A0076207D /* Help.swift */; };
B5A3F36A1F0FE241008E44BF /* PinterestLayoutDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A3F3691F0FE241008E44BF /* PinterestLayoutDelegate.swift */; };
B5A3F36C1F0FE25F008E44BF /* PinterestLayoutAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A3F36B1F0FE25F008E44BF /* PinterestLayoutAttributes.swift */; };
B5AFCBAC1F0BB16F00CB71B5 /* PinterestLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = B5AFCBAA1F0BB16F00CB71B5 /* PinterestLayout.h */; settings = {ATTRIBUTES = (Public, ); }; };
B5CF9EDE1F0BB19500DAA3B7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CF9EDD1F0BB19500DAA3B7 /* AppDelegate.swift */; };
B5CF9EE01F0BB19500DAA3B7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CF9EDF1F0BB19500DAA3B7 /* ViewController.swift */; };
B5CF9EE01F0BB19500DAA3B7 /* MyPinterestVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CF9EDF1F0BB19500DAA3B7 /* MyPinterestVC.swift */; };
B5CF9EE31F0BB19500DAA3B7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B5CF9EE11F0BB19500DAA3B7 /* Main.storyboard */; };
B5CF9EE51F0BB19500DAA3B7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B5CF9EE41F0BB19500DAA3B7 /* Assets.xcassets */; };
B5CF9EE81F0BB19500DAA3B7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B5CF9EE61F0BB19500DAA3B7 /* LaunchScreen.storyboard */; };
B5CF9EED1F0BB1A800DAA3B7 /* PinterestLayout.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5AFCBA71F0BB16F00CB71B5 /* PinterestLayout.framework */; };
B5CF9EEE1F0BB1A800DAA3B7 /* PinterestLayout.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = B5AFCBA71F0BB16F00CB71B5 /* PinterestLayout.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
B5CF9EF31F0BB1D200DAA3B7 /* PinterestLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CF9EF21F0BB1D200DAA3B7 /* PinterestLayout.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -43,14 +52,23 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
640095F61F0BC37F006AE391 /* CollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewCell.swift; sourceTree = "<group>"; };
644F27A91F0BF039004AD5AD /* RoundedCornersView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoundedCornersView.swift; sourceTree = "<group>"; };
646640331F0F99470076207D /* PinterestCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinterestCell.swift; sourceTree = "<group>"; };
646640371F0FD05A0076207D /* Help.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Help.swift; sourceTree = "<group>"; };
B572E5EE1F0C20D100540F7C /* PinterestHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinterestHeader.swift; sourceTree = "<group>"; };
B5A3F3601F0FDFD3008E44BF /* CustomCollectionVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomCollectionVC.swift; sourceTree = "<group>"; };
B5A3F3621F0FE119008E44BF /* PinterestVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinterestVC.swift; sourceTree = "<group>"; };
B5A3F3691F0FE241008E44BF /* PinterestLayoutDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinterestLayoutDelegate.swift; sourceTree = "<group>"; };
B5A3F36B1F0FE25F008E44BF /* PinterestLayoutAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinterestLayoutAttributes.swift; sourceTree = "<group>"; };
B5AFCBA71F0BB16F00CB71B5 /* PinterestLayout.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PinterestLayout.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B5AFCBAA1F0BB16F00CB71B5 /* PinterestLayout.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PinterestLayout.h; sourceTree = "<group>"; };
B5AFCBAB1F0BB16F00CB71B5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B5CF9EDB1F0BB19500DAA3B7 /* PinterestLayoutExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PinterestLayoutExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
B5CF9EDD1F0BB19500DAA3B7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
B5CF9EDF1F0BB19500DAA3B7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
B5CF9EDF1F0BB19500DAA3B7 /* MyPinterestVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPinterestVC.swift; sourceTree = "<group>"; };
B5CF9EE21F0BB19500DAA3B7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
B5CF9EE41F0BB19500DAA3B7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
B5CF9EE41F0BB19500DAA3B7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = PinterestLayoutExample/Assets.xcassets; sourceTree = SOURCE_ROOT; };
B5CF9EE71F0BB19500DAA3B7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
B5CF9EE91F0BB19500DAA3B7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B5CF9EF21F0BB1D200DAA3B7 /* PinterestLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinterestLayout.swift; sourceTree = "<group>"; };
Expand All @@ -75,6 +93,43 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
640095F41F0BC340006AE391 /* UI */ = {
isa = PBXGroup;
children = (
640095F51F0BC34D006AE391 /* Views */,
B5CF9EE11F0BB19500DAA3B7 /* Main.storyboard */,
B5CF9EE61F0BB19500DAA3B7 /* LaunchScreen.storyboard */,
);
name = UI;
sourceTree = "<group>";
};
640095F51F0BC34D006AE391 /* Views */ = {
isa = PBXGroup;
children = (
640095F61F0BC37F006AE391 /* CollectionViewCell.swift */,
644F27A91F0BF039004AD5AD /* RoundedCornersView.swift */,
B572E5EE1F0C20D100540F7C /* PinterestHeader.swift */,
);
name = Views;
sourceTree = "<group>";
};
640095F81F0BC3E8006AE391 /* Recourses */ = {
isa = PBXGroup;
children = (
B5CF9EE41F0BB19500DAA3B7 /* Assets.xcassets */,
);
name = Recourses;
path = ../PinterestLayout;
sourceTree = "<group>";
};
B572E5ED1F0C0D5500540F7C /* Supporting Files */ = {
isa = PBXGroup;
children = (
B5CF9EE91F0BB19500DAA3B7 /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
B5AFCB9D1F0BB16F00CB71B5 = {
isa = PBXGroup;
children = (
Expand All @@ -97,8 +152,13 @@
isa = PBXGroup;
children = (
B5AFCBAA1F0BB16F00CB71B5 /* PinterestLayout.h */,
B5AFCBAB1F0BB16F00CB71B5 /* Info.plist */,
B5A3F3691F0FE241008E44BF /* PinterestLayoutDelegate.swift */,
B5A3F36B1F0FE25F008E44BF /* PinterestLayoutAttributes.swift */,
B5CF9EF21F0BB1D200DAA3B7 /* PinterestLayout.swift */,
B5A3F3621F0FE119008E44BF /* PinterestVC.swift */,
646640331F0F99470076207D /* PinterestCell.swift */,
646640371F0FD05A0076207D /* Help.swift */,
B5AFCBAB1F0BB16F00CB71B5 /* Info.plist */,
);
path = PinterestLayout;
sourceTree = "<group>";
Expand All @@ -107,11 +167,11 @@
isa = PBXGroup;
children = (
B5CF9EDD1F0BB19500DAA3B7 /* AppDelegate.swift */,
B5CF9EDF1F0BB19500DAA3B7 /* ViewController.swift */,
B5CF9EE11F0BB19500DAA3B7 /* Main.storyboard */,
B5CF9EE41F0BB19500DAA3B7 /* Assets.xcassets */,
B5CF9EE61F0BB19500DAA3B7 /* LaunchScreen.storyboard */,
B5CF9EE91F0BB19500DAA3B7 /* Info.plist */,
B5CF9EDF1F0BB19500DAA3B7 /* MyPinterestVC.swift */,
B5A3F3601F0FDFD3008E44BF /* CustomCollectionVC.swift */,
640095F41F0BC340006AE391 /* UI */,
640095F81F0BC3E8006AE391 /* Recourses */,
B572E5ED1F0C0D5500540F7C /* Supporting Files */,
);
path = PinterestLayoutExample;
sourceTree = "<group>";
Expand Down Expand Up @@ -234,16 +294,25 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B5CF9EF31F0BB1D200DAA3B7 /* PinterestLayout.swift in Sources */,
B5A3F3651F0FE1D1008E44BF /* PinterestCell.swift in Sources */,
B5A3F3641F0FE1C2008E44BF /* PinterestLayout.swift in Sources */,
B5A3F3631F0FE119008E44BF /* PinterestVC.swift in Sources */,
B5A3F36A1F0FE241008E44BF /* PinterestLayoutDelegate.swift in Sources */,
B5A3F36C1F0FE25F008E44BF /* PinterestLayoutAttributes.swift in Sources */,
B5A3F3661F0FE1D4008E44BF /* Help.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
B5CF9ED71F0BB19500DAA3B7 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B5CF9EE01F0BB19500DAA3B7 /* ViewController.swift in Sources */,
B5CF9EE01F0BB19500DAA3B7 /* MyPinterestVC.swift in Sources */,
B5CF9EDE1F0BB19500DAA3B7 /* AppDelegate.swift in Sources */,
B5A3F3611F0FDFD3008E44BF /* CustomCollectionVC.swift in Sources */,
640095F71F0BC37F006AE391 /* CollectionViewCell.swift in Sources */,
644F27AA1F0BF039004AD5AD /* RoundedCornersView.swift in Sources */,
B572E5EF1F0C20D100540F7C /* PinterestHeader.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -479,6 +548,7 @@
B5CF9EEB1F0BB19500DAA3B7 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
109 changes: 109 additions & 0 deletions PinterestLayout/Help.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// UIView+Constraints.swift
// PinterestLayout
//
// Created by Khrystyna Shevchuk on 7/7/17.
// Copyright © 2017 MagicLab. All rights reserved.
//

import UIKit
import AVFoundation


public extension UIImage {
/**
Calculates the best height of the image for available width.
*/
public func height(forWidth width: CGFloat) -> CGFloat {
let boundingRect = CGRect(
x: 0,
y: 0,
width: width,
height: CGFloat(MAXFLOAT)
)
let rect = AVMakeRect(
aspectRatio: size,
insideRect: boundingRect
)
return rect.size.height
}
}


public extension String {
/**
Calculates the best height of the text for available width and font used.
*/
public func heightForWidth(width: CGFloat, font: UIFont) -> CGFloat {
let rect = NSString(string: self).boundingRect(
with: CGSize(width: width, height: CGFloat(MAXFLOAT)),
options: .usesLineFragmentOrigin,
attributes: [NSFontAttributeName: font],
context: nil
)
return ceil(rect.height)
}
}

extension UIFont {

class var defaultFont: UIFont {
return UIFont(name: "Arial-ItalicMT", size: 11)!
}
}


extension UIView {

func addConstraintsAlignedToSuperview(top: CGFloat = 0,
leading: CGFloat = 0,
bottom: CGFloat = 0,
trailing: CGFloat = 0) {
translatesAutoresizingMaskIntoConstraints = false

superview?.addConstraint(
NSLayoutConstraint(
item: self,
attribute: .top,
relatedBy: .equal,
toItem: superview,
attribute: .top,
multiplier: 1,
constant: top
)
)
superview?.addConstraint(
NSLayoutConstraint(
item: self,
attribute: .leading,
relatedBy: .equal,
toItem: superview,
attribute: .leading,
multiplier: 1,
constant: leading
)
)
superview?.addConstraint(
NSLayoutConstraint(
item: self,
attribute: .bottom,
relatedBy: .equal,
toItem: superview,
attribute: .bottom,
multiplier: 1,
constant: bottom
)
)
superview?.addConstraint(
NSLayoutConstraint(
item: self,
attribute: .trailing,
relatedBy: .equal,
toItem: superview,
attribute: .trailing,
multiplier: 1,
constant: trailing
)
)
}
}
Loading