diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/Source/TagCellLayout+Helper.swift b/Source/TagCellLayout+Helper.swift old mode 100644 new mode 100755 diff --git a/Source/TagCellLayout.swift b/Source/TagCellLayout.swift old mode 100644 new mode 100755 index 741dcee..8411295 --- a/Source/TagCellLayout.swift +++ b/Source/TagCellLayout.swift @@ -56,7 +56,7 @@ public class TagCellLayout: UICollectionViewLayout { position.x += info.bounds.width return position } - return CGPointZero + return .zero } var currentTagLayoutInfo: TagCellLayoutInfo? { @@ -68,7 +68,7 @@ public class TagCellLayout: UICollectionViewLayout { } var tagsCount: Int { - return collectionView?.numberOfItemsInSection(0) ?? 0 + return collectionView?.numberOfItems(inSection: 0) ?? 0 } var collectionViewWidth: CGFloat { @@ -97,39 +97,38 @@ public class TagCellLayout: UICollectionViewLayout { //MARK: - Override Methods - override public func prepareLayout() { + override public func prepare() { resetLayoutState() setupTagCellLayout() } - - override public func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? { - if layoutInfoList.count > indexPath.row { - return layoutInfoList[indexPath.row].layoutAttribute - } - - return nil - } - - override public func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? { + public override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { + if layoutInfoList.count > indexPath.row { + return layoutInfoList[indexPath.row].layoutAttribute + } + + return nil + } + + override public func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { if layoutInfoList.count > 0 { let visibleLayoutAttributes = layoutInfoList .map { $0.layoutAttribute } - .filter { CGRectIntersectsRect(rect, $0.frame) } + .filter { rect.intersects($0.frame) } return visibleLayoutAttributes } return nil } - override public func collectionViewContentSize() -> CGSize { - if let - heightPerLine = delegate?.tagCellLayoutTagFixHeight(self), - width = collectionView?.frame.size.width - { - let height = heightPerLine*CGFloat(lineNumber) - return CGSize(width: width, height: height) - } - return CGSize.zero - } + override public var collectionViewContentSize: CGSize { + if let + heightPerLine = delegate?.tagCellLayoutTagFixHeight(layout: self), + let width = collectionView?.frame.size.width + { + let height = heightPerLine*CGFloat(lineNumber) + return CGSize(width: width, height: height) + } + return CGSize.zero + } public class func textWidth(text: String, font: UIFont) -> CGFloat { let padding: CGFloat = 4 // this number is independent of font and is required to compensate the inaccuracy of sizeToFit calculation! @@ -148,9 +147,9 @@ private extension TagCellLayout { func setupTagCellLayout() { // delegate and collectionview shouldn't be nil - if let delegate = delegate where collectionView != nil { + if let delegate = delegate , let _ = collectionView { // basic layout setup which is independent of TagAlignment type - basicLayoutSetup(delegate) + basicLayoutSetup(delegate: delegate) // handle if TagAlignment is other than Left handleTagAlignment() @@ -185,11 +184,11 @@ private extension TagCellLayout { func createLayoutAttributes() { if let delegate = delegate { // calculating tag-size - let tagHeight = delegate.tagCellLayoutTagFixHeight(self) - let tagWidth = delegate.tagCellLayoutTagWidth(self, atIndex: currentTagIndex) - let tagSize = CGSizeMake(tagWidth, tagHeight) + let tagHeight = delegate.tagCellLayoutTagFixHeight(layout: self) + let tagWidth = delegate.tagCellLayoutTagWidth(layout: self, atIndex: currentTagIndex) + let tagSize = CGSize(width: tagWidth, height: tagHeight) - let layoutInfo = tagCellLayoutInfo(currentTagIndex, tagSize: tagSize) + let layoutInfo = tagCellLayoutInfo(tagIndex: currentTagIndex, tagSize: tagSize) layoutInfoList.append(layoutInfo) } } @@ -199,11 +198,11 @@ private extension TagCellLayout { var tagFrame = CGRect(origin: currentTagPosition, size: tagSize) // if next tag goes out of screen then move it to next row - if shouldMoveTagToNextRow(tagSize.width) { + if shouldMoveTagToNextRow(tagWidth: tagSize.width) { tagFrame.origin.x = 0 tagFrame.origin.y += tagSize.height } - let attribute = layoutAttribute(tagIndex, tagFrame: tagFrame) + let attribute = layoutAttribute(tagIndex: tagIndex, tagFrame: tagFrame) let info = TagCellLayoutInfo(layoutAttribute: attribute) return info } @@ -213,8 +212,8 @@ private extension TagCellLayout { } func layoutAttribute(tagIndex: Int, tagFrame: CGRect) -> UICollectionViewLayoutAttributes { - let indexPath = NSIndexPath(forItem: tagIndex, inSection: 0) - let layoutAttribute = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath) + let indexPath = IndexPath(item: tagIndex, section: 0) + let layoutAttribute = UICollectionViewLayoutAttributes(forCellWith: indexPath) layoutAttribute.frame = tagFrame return layoutAttribute } @@ -222,23 +221,23 @@ private extension TagCellLayout { func configureWhiteSpace() { let layoutInfo = layoutInfoList[currentTagIndex].layoutAttribute let tagWidth = layoutInfo.frame.size.width - if shouldMoveTagToNextRow(tagWidth) { + if shouldMoveTagToNextRow(tagWidth: tagWidth) { lineNumber += 1 applyWhiteSpace(startingIndex: (currentTagIndex - 1)) } } - func applyWhiteSpace(startingIndex startingIndex: Int) { + func applyWhiteSpace(startingIndex: Int) { let lastIndex = startingIndex - numberOfTagsInCurrentRow - let whiteSpace = calculateWhiteSpace(startingIndex) + let whiteSpace = calculateWhiteSpace(tagIndex: startingIndex) for tagIndex in (lastIndex+1) ..< (startingIndex+1) { - insertWhiteSpace(tagIndex, whiteSpace: whiteSpace) + insertWhiteSpace(tagIndex: tagIndex, whiteSpace: whiteSpace) } } func calculateWhiteSpace(tagIndex: Int) -> CGFloat { - let tagFrame = tagFrameForIndex(tagIndex) + let tagFrame = tagFrameForIndex(tagIndex: tagIndex) let whiteSpace = collectionViewWidth - (tagFrame.origin.x + tagFrame.size.width) return whiteSpace } @@ -251,28 +250,30 @@ private extension TagCellLayout { } func tagFrameForIndex(tagIndex: Int) -> CGRect { - let tagFrame = tagIndex > -1 ? layoutInfoList[tagIndex].layoutAttribute.frame : CGRectZero + let tagFrame = tagIndex > -1 ? layoutInfoList[tagIndex].layoutAttribute.frame : .zero return tagFrame } func configurePositionForNextTag() { let layoutInfo = layoutInfoList[currentTagIndex].layoutAttribute - let moveTag = shouldMoveTagToNextRow(layoutInfo.frame.size.width) + let moveTag = shouldMoveTagToNextRow(tagWidth: layoutInfo.frame.size.width) numberOfTagsInCurrentRow = moveTag ? 1 : (numberOfTagsInCurrentRow + 1) } - - func handleTagAlignment() { - if let collectionView = collectionView where tagAlignmentType != .Left { - let tagsCount = collectionView.numberOfItemsInSection(0) - for tagIndex in 0 ..< tagsCount { - var tagFrame = layoutInfoList[tagIndex].layoutAttribute.frame - let whiteSpace = layoutInfoList[tagIndex].whiteSpace - tagFrame.origin.x += whiteSpace - let tagAttribute = layoutAttribute(tagIndex, tagFrame: tagFrame) - layoutInfoList[tagIndex].layoutAttribute = tagAttribute - } - } - } + + func handleTagAlignment() { + if let collectionView = collectionView { + if tagAlignmentType != .Left { + let tagsCount = collectionView.numberOfItems(inSection: 0) + for tagIndex in 0 ..< tagsCount { + var tagFrame = layoutInfoList[tagIndex].layoutAttribute.frame + let whiteSpace = layoutInfoList[tagIndex].whiteSpace + tagFrame.origin.x += whiteSpace + let tagAttribute = layoutAttribute(tagIndex: tagIndex, tagFrame: tagFrame) + layoutInfoList[tagIndex].layoutAttribute = tagAttribute + } + } + } + } func handleWhiteSpaceForLastRow() { if isLastRow { diff --git a/TagCellLayout.podspec b/TagCellLayout.podspec old mode 100644 new mode 100755 diff --git a/TagCellLayout.xcodeproj/project.pbxproj b/TagCellLayout.xcodeproj/project.pbxproj old mode 100644 new mode 100755 index d824d96..7a8b53b --- a/TagCellLayout.xcodeproj/project.pbxproj +++ b/TagCellLayout.xcodeproj/project.pbxproj @@ -279,6 +279,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.Ritesh.TagCellLayout; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = "ff255666-24e2-4500-b9ea-19ca6b2df949"; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -293,6 +294,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.Ritesh.TagCellLayout; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = "ff255666-24e2-4500-b9ea-19ca6b2df949"; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/TagCellLayout.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/TagCellLayout.xcodeproj/project.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/TagCellLayout.xcodeproj/xcshareddata/xcschemes/TagCellLayout.xcscheme b/TagCellLayout.xcodeproj/xcshareddata/xcschemes/TagCellLayout.xcscheme old mode 100644 new mode 100755 diff --git a/TagCellLayout.xcodeproj/xcuserdata/riteshgupta.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/TagCellLayout.xcodeproj/xcuserdata/riteshgupta.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist old mode 100644 new mode 100755 diff --git a/TagCellLayout.xcodeproj/xcuserdata/riteshgupta.xcuserdatad/xcschemes/xcschememanagement.plist b/TagCellLayout.xcodeproj/xcuserdata/riteshgupta.xcuserdatad/xcschemes/xcschememanagement.plist old mode 100644 new mode 100755 diff --git a/TagCellLayout/AppDelegate.swift b/TagCellLayout/AppDelegate.swift old mode 100644 new mode 100755 diff --git a/TagCellLayout/Assets.xcassets/AppIcon.appiconset/Contents.json b/TagCellLayout/Assets.xcassets/AppIcon.appiconset/Contents.json old mode 100644 new mode 100755 diff --git a/TagCellLayout/Base.lproj/LaunchScreen.storyboard b/TagCellLayout/Base.lproj/LaunchScreen.storyboard old mode 100644 new mode 100755 diff --git a/TagCellLayout/Base.lproj/Main.storyboard b/TagCellLayout/Base.lproj/Main.storyboard old mode 100644 new mode 100755 index 645f146..6bf9fe3 --- a/TagCellLayout/Base.lproj/Main.storyboard +++ b/TagCellLayout/Base.lproj/Main.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -14,12 +18,12 @@ - + - - + + @@ -28,7 +32,7 @@ - + diff --git a/TagCellLayout/Info.plist b/TagCellLayout/Info.plist old mode 100644 new mode 100755 diff --git a/TagCellLayout/Readme_Resources/tag_cc.png b/TagCellLayout/Readme_Resources/tag_cc.png old mode 100644 new mode 100755 diff --git a/TagCellLayout/Readme_Resources/tag_ll.png b/TagCellLayout/Readme_Resources/tag_ll.png old mode 100644 new mode 100755 diff --git a/TagCellLayout/Readme_Resources/tag_rr.png b/TagCellLayout/Readme_Resources/tag_rr.png old mode 100644 new mode 100755 diff --git a/TagCellLayout/TagCollectionViewCell.swift b/TagCellLayout/TagCollectionViewCell.swift old mode 100644 new mode 100755 index 826fb9a..9e38686 --- a/TagCellLayout/TagCollectionViewCell.swift +++ b/TagCellLayout/TagCollectionViewCell.swift @@ -16,9 +16,9 @@ class TagCollectionViewCell: UICollectionViewCell { override func awakeFromNib() { if let tagView = tagView { tagView.layer.cornerRadius = tagView.frame.size.height/2 - 2 - tagView.layer.borderColor = UIColor.blueColor().CGColor + tagView.layer.borderColor = UIColor.blue.cgColor tagView.layer.borderWidth = 3.0 } } -} \ No newline at end of file +} diff --git a/TagCellLayout/TagCollectionViewCell.xib b/TagCellLayout/TagCollectionViewCell.xib old mode 100644 new mode 100755 index 48e0372..0a3b370 --- a/TagCellLayout/TagCollectionViewCell.xib +++ b/TagCellLayout/TagCollectionViewCell.xib @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -16,13 +20,12 @@ - diff --git a/TagCellLayout/ViewController.swift b/TagCellLayout/ViewController.swift old mode 100644 new mode 100755 index 845f4ac..5b895c5 --- a/TagCellLayout/ViewController.swift +++ b/TagCellLayout/ViewController.swift @@ -17,7 +17,7 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi // Do any additional setup after loading the view, typically from a nib. } - override func viewDidAppear(animated: Bool) { + override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) defaultSetup() @@ -46,14 +46,14 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi func defaultSetup() { let nib = UINib(nibName: "TagCollectionViewCell", bundle: nil) - collectionView?.registerNib(nib, forCellWithReuseIdentifier: "TagCollectionViewCell") + collectionView?.register(nib, forCellWithReuseIdentifier: "TagCollectionViewCell") } //MARK: - UICollectionView Delegate/Datasource Methods - func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let identifier = "TagCollectionViewCell" - let cell = collectionView.dequeueReusableCellWithReuseIdentifier(identifier, forIndexPath: indexPath) + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) return cell } @@ -61,7 +61,7 @@ class ViewController: UIViewController, UICollectionViewDelegate, UICollectionVi return 1 } - func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 10 }