From e14c5c0b168d32fccd3e28979887f36799194802 Mon Sep 17 00:00:00 2001 From: Michael Galperin Date: Wed, 21 Dec 2016 23:44:54 +0300 Subject: [PATCH 01/13] Code examples updated to Swift 3 --- README.md | 76 +++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 25fa44d..aa52fb1 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ You can initialize a `Segmentio` instance from code: ```swift var segmentioView: Segmentio! -let segmentioViewRect = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 125) +let segmentioViewRect = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 125) segmentioView = Segmentio(frame: segmentioViewRect) view.addSubview(segmentioView) ``` @@ -56,7 +56,7 @@ add a `UIView` instance in your .storyboard or .xib, set `Segmentio` class and c ####Setup `Segmentio` ```swift -segmentioView.setupContent( +segmentioView.setup( content: [SegmentioItem], style: SegmentioStyle, options: SegmentioOptions? @@ -66,7 +66,7 @@ segmentioView.setupContent( To start with default options you can just pass `nil` to the `options` parameter. ```swift -segmentioView.setupContent( +segmentioView.setup( content: [SegmentioItem], style: SegmentioStyle, options: nil @@ -91,7 +91,7 @@ content.append(tornadoItem) You can specify selected item manually: ```swift -segmentioView.selectedSegmentIndex = 0 +segmentioView.selectedSegmentioIndex = 0 ``` ####Handling callback @@ -107,17 +107,15 @@ segmentioView.valueDidChange = { segmentio, segmentIndex in ```swift SegmentioOptions( - backgroundColor: UIColor.whiteColor(), - maxVisibleItems: 3, - scrollEnabled: true, - indicatorOptions: SegmentioIndicatorOptions, - horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions, - verticalSeparatorOptions: SegmentioVerticalSeparatorOptions, - imageContentMode: UIViewContentMode.Center, - labelTextNumberOfLines: 1, - labelTextAlignment: NSTextAlignment.Center, - segmentStates: SegmentioStates, // tuple of SegmentioState (defaultState, selectState, highlightedState) - animationDuration: 0.1 + backgroundColor: .white, + maxVisibleItems: 3, + scrollEnabled: true, + indicatorOptions: SegmentioIndicatorOptions, + horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions, + verticalSeparatorOptions: SegmentioVerticalSeparatorOptions, + imageContentMode: .center, + labelTextAlignment: .center, + segmentStates: SegmentioStates ) ``` @@ -125,10 +123,10 @@ Selection indicator can be customized by passing an instance of `SegmentioIndica ```swift SegmentioIndicatorOptions( - type: .Bottom, - ratio: 1, - height: 5, - color: UIColor.orangeColor() + type: .bottom, + ratio: 1, + height: 5, + color: .orange ) ``` @@ -136,9 +134,9 @@ Horizontal borders can be customized by passing an instance of `SegmentioHorizon ```swift SegmentioHorizontalSeparatorOptions( - type: SegmentioHorizontalSeparatorType.TopAndBottom, // Top, Bottom, TopAndBottom - height: 1, - color: UIColor.grayColor() + type: SegmentioHorizontalSeparatorType.topAndBottom, // Top, Bottom, TopAndBottom + height: 1, + color: .gray ) ``` @@ -146,8 +144,8 @@ Separators between segments can be customized by passing an instance of `Segmen ```swift SegmentioVerticalSeparatorOptions( - ratio: 0.6 // from 0.1 to 1 - color: UIColor.grayColor() + ratio: 0.6, // from 0.1 to 1 + color: .gray ) ``` @@ -155,21 +153,21 @@ In order to set `SegmentioStates` you need to create a tuple of `SegmentioState` ```swift SegmentioStates( - defaultState: segmentioState( - backgroundColor: UIColor.clearColor(), - titleFont: UIFont.systemFontOfSize(UIFont.smallSystemFontSize()), - titleTextColor: UIColor.blackColor() - ), - selectState: segmentioState( - backgroundColor: UIColor.orangeColor(), - titleFont: UIFont.systemFontOfSize(UIFont.smallSystemFontSize()), - titleTextColor: UIColor.whiteColor() - ), - highlightedState: segmentioState( - backgroundColor: UIColor.lightGrayColor().colorWithAlphaComponent(0.6), - titleFont: UIFont.boldSystemFontOfSize(UIFont.smallSystemFontSize()), - titleTextColor: UIColor.blackColor() - ) + defaultState: SegmentioState( + backgroundColor: .clear, + titleFont: UIFont.systemFont(ofSize: UIFont.smallSystemFontSize), + titleTextColor: .black + ), + selectedState: SegmentioState( + backgroundColor: .orange, + titleFont: UIFont.systemFont(ofSize: UIFont.smallSystemFontSize), + titleTextColor: .white + ), + highlightedState: SegmentioState( + backgroundColor: UIColor.lightGray.withAlphaComponent(0.6), + titleFont: UIFont.boldSystemFont(ofSize: UIFont.smallSystemFontSize), + titleTextColor: .black + ) ) ``` From 8042192731305300edc56f0dcc63f903c5c14f2c Mon Sep 17 00:00:00 2001 From: Boris Vinogradov Date: Fri, 13 Jan 2017 12:42:00 +0200 Subject: [PATCH 02/13] Update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 228d900..7dda022 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright © 2016 Yalantis +Copyright © 2017 Yalantis Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 51f08913fb73c5c0af5d6c9be34d825632cb6ace Mon Sep 17 00:00:00 2001 From: Boris Vinogradov Date: Fri, 13 Jan 2017 12:42:25 +0200 Subject: [PATCH 03/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aa52fb1..89702bb 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ P.S. We’re going to publish more awesomeness wrapped in code and a tutorial on The MIT License (MIT) -Copyright © 2016 Yalantis +Copyright © 2017 Yalantis Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 8a21e29e892b995ed271f9b5c4a817914e41ae41 Mon Sep 17 00:00:00 2001 From: Serhii Butenko Date: Tue, 17 Jan 2017 08:46:08 +0200 Subject: [PATCH 04/13] Fix word overbounds (closes #16) --- Segmentio.podspec | 2 +- Segmentio/Source/Cells/SegmentioCell.swift | 57 ++++++++++++---------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/Segmentio.podspec b/Segmentio.podspec index f09fb14..d32a0ae 100644 --- a/Segmentio.podspec +++ b/Segmentio.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "Segmentio" - spec.version = "2.1.1" + spec.version = "2.1.2" spec.homepage = "https://github.com/Yalantis/Segmentio" spec.summary = "Animated top/bottom segmented control written in Swift!" diff --git a/Segmentio/Source/Cells/SegmentioCell.swift b/Segmentio/Source/Cells/SegmentioCell.swift index bbc69f6..af70d89 100644 --- a/Segmentio/Source/Cells/SegmentioCell.swift +++ b/Segmentio/Source/Cells/SegmentioCell.swift @@ -173,38 +173,43 @@ class SegmentioCell: UICollectionViewCell { // MARK: - Private functions fileprivate func setupContainerConstraints() { - guard let segmentTitleLabel = segmentTitleLabel else { - return - } - guard let containerView = containerView else { + guard let segmentTitleLabel = segmentTitleLabel, let containerView = containerView else { return } - let segmentTitleLabelHorizontalCenterConstraint = - NSLayoutConstraint( - item: segmentTitleLabel, - attribute: .centerX, - relatedBy: .equal, - toItem: containerView, - attribute: .centerX, - multiplier: 1, - constant: 0 + let segmentTitleLabelVerticalCenterConstraint = NSLayoutConstraint( + item: segmentTitleLabel, + attribute: .centerY, + relatedBy: .equal, + toItem: containerView, + attribute: .centerY, + multiplier: 1, + constant: 0 + ) + let segmentTitleLabelTrailingConstraint = NSLayoutConstraint( + item: segmentTitleLabel, + attribute: .trailing, + relatedBy: .equal, + toItem: containerView, + attribute: .trailingMargin, + multiplier: 1.0, + constant: 0 + ) + let segmentTitleLabelLeadingConstraint = NSLayoutConstraint( + item: segmentTitleLabel, + attribute: .leading, + relatedBy: .equal, + toItem: containerView, + attribute: .leadingMargin, + multiplier: 1.0, + constant: 0 ) - let segmentTitleLabelVerticalCenterConstraint = - NSLayoutConstraint( - item: segmentTitleLabel, - attribute: .centerY, - relatedBy: .equal, - toItem: containerView, - attribute: .centerY, - multiplier: 1, - constant: 0 - ) addConstraints([ - segmentTitleLabelHorizontalCenterConstraint, - segmentTitleLabelVerticalCenterConstraint - ]) + segmentTitleLabelTrailingConstraint, + segmentTitleLabelVerticalCenterConstraint, + segmentTitleLabelLeadingConstraint + ]) } fileprivate func setupImageContainerConstraints() { From 762b7b17cb5d404ba331037f77a35166eddb98f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aure=CC=81lien=20Grifasi?= Date: Thu, 17 Aug 2017 16:04:10 +0200 Subject: [PATCH 05/13] add accessibilityIdentifier on collection view to be accessible. By example with the KIF interface testing library (https://github.com/kif-framework/KIF) --- Segmentio/Source/Segmentio.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Segmentio/Source/Segmentio.swift b/Segmentio/Source/Segmentio.swift index b4797b9..578442e 100644 --- a/Segmentio/Source/Segmentio.swift +++ b/Segmentio/Source/Segmentio.swift @@ -96,6 +96,7 @@ open class Segmentio: UIView { collectionView.bounces = true collectionView.isScrollEnabled = segmentioOptions.scrollEnabled collectionView.backgroundColor = .clear + collectionView.accessibilityIdentifier = "segmentio_collection_view" segmentioCollectionView = collectionView From 42f55d33d20c986f6dcdbb0cf67d1fb94c19fd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Pereira?= Date: Thu, 17 Aug 2017 15:11:43 +0100 Subject: [PATCH 06/13] Add selected image --- Segmentio/Source/Cells/SegmentioCell.swift | 8 +++++++- Segmentio/Source/Segmentio.swift | 6 ++++-- Segmentio/Source/SegmentioOptions.swift | 4 +++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Segmentio/Source/Cells/SegmentioCell.swift b/Segmentio/Source/Cells/SegmentioCell.swift index af70d89..187e6fd 100644 --- a/Segmentio/Source/Cells/SegmentioCell.swift +++ b/Segmentio/Source/Cells/SegmentioCell.swift @@ -130,7 +130,7 @@ class SegmentioCell: UICollectionViewCell { configurateBadgeWithCount(content.badgeCount, color: content.badgeColor) } - func configure(selected: Bool) { + func configure(selected: Bool, selectedImage:UIImage? = nil, image:UIImage? = nil) { cellSelected = selected let selectedState = options.states.selectedState @@ -140,6 +140,12 @@ class SegmentioCell: UICollectionViewCell { segmentTitleLabel?.textColor = selected ? selectedState.titleTextColor : defaultState.titleTextColor segmentTitleLabel?.font = selected ? selectedState.titleFont : defaultState.titleFont } + + backgroundColor = selected ? selectedState.backgroundColor : defaultState.backgroundColor + + if (style != .onlyLabel) { + segmentImageView?.image = selected ? selectedImage : image + } } func configurateBadgeWithCount(_ badgeCount: Int?, color: UIColor?) { diff --git a/Segmentio/Source/Segmentio.swift b/Segmentio/Source/Segmentio.swift index b4797b9..783eafc 100644 --- a/Segmentio/Source/Segmentio.swift +++ b/Segmentio/Source/Segmentio.swift @@ -536,14 +536,16 @@ extension Segmentio: UICollectionViewDataSource { withReuseIdentifier: segmentioStyle.rawValue, for: indexPath) as! SegmentioCell + let content = segmentioItems[indexPath.row] + cell.configure( - content: segmentioItems[indexPath.row], + content: content, style: segmentioStyle, options: segmentioOptions, isLastCell: indexPath.row == segmentioItems.count - 1 ) - cell.configure(selected: (indexPath.row == selectedSegmentioIndex)) + cell.configure(selected: (indexPath.row == selectedSegmentioIndex), selectedImage:content.selectedImage, image:content.image) return cell } diff --git a/Segmentio/Source/SegmentioOptions.swift b/Segmentio/Source/SegmentioOptions.swift index 9c6f641..3addf9c 100644 --- a/Segmentio/Source/SegmentioOptions.swift +++ b/Segmentio/Source/SegmentioOptions.swift @@ -14,12 +14,14 @@ public struct SegmentioItem { public var title: String? public var image: UIImage? + public var selectedImage: UIImage? public var badgeCount: Int? public var badgeColor: UIColor? - public init(title: String?, image: UIImage?) { + public init(title: String?, image: UIImage?, selectedImage: UIImage? = nil) { self.title = title self.image = image + self.selectedImage = selectedImage } public mutating func addBadge(_ count: Int, color: UIColor) { From 85bed4548be731923793cc94a8250b82bee5c5bd Mon Sep 17 00:00:00 2001 From: pauluhn Date: Thu, 17 Aug 2017 16:55:55 -0500 Subject: [PATCH 07/13] Add horizontal separator none. --- Segmentio/Source/Segmentio.swift | 4 ++++ Segmentio/Source/SegmentioOptions.swift | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Segmentio/Source/Segmentio.swift b/Segmentio/Source/Segmentio.swift index b4797b9..da082a7 100644 --- a/Segmentio/Source/Segmentio.swift +++ b/Segmentio/Source/Segmentio.swift @@ -112,6 +112,8 @@ open class Segmentio: UIView { let separatorHeight = horizontalSeparatorOptions.height switch horizontalSeparatorOptions.type { + case .none: + separatorsHeight = 0 case .top: collectionViewFrameMinY = separatorHeight separatorsHeight = separatorHeight @@ -511,6 +513,8 @@ open class Segmentio: UIView { let isIndicatorTop = indicatorOptions.type == .top switch horizontalSeparatorOptions.type { + case .none: + break case .top: indicatorPointY = isIndicatorTop ? indicatorPointY + separatorHeight : indicatorPointY case .bottom: diff --git a/Segmentio/Source/SegmentioOptions.swift b/Segmentio/Source/SegmentioOptions.swift index 9c6f641..41cd185 100644 --- a/Segmentio/Source/SegmentioOptions.swift +++ b/Segmentio/Source/SegmentioOptions.swift @@ -56,7 +56,7 @@ public struct SegmentioState { // MARK: - Horizontal separator public enum SegmentioHorizontalSeparatorType { - + case none case top case bottom case topAndBottom From 1b6a38609ef0691195586d54845210804fdc4135 Mon Sep 17 00:00:00 2001 From: pauluhn Date: Thu, 17 Aug 2017 18:09:58 -0500 Subject: [PATCH 08/13] Fix UI bug. --- Segmentio/Source/Segmentio.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Segmentio/Source/Segmentio.swift b/Segmentio/Source/Segmentio.swift index da082a7..ad7f709 100644 --- a/Segmentio/Source/Segmentio.swift +++ b/Segmentio/Source/Segmentio.swift @@ -253,7 +253,7 @@ open class Segmentio: UIView { bottomSeparatorView = UIView(frame: CGRect.zero) setupConstraintsForSeparatorView( separatorView: bottomSeparatorView, - originY: frame.maxY - height + originY: bounds.maxY - height ) } } @@ -271,7 +271,7 @@ open class Segmentio: UIView { item: separatorView, attribute: .top, relatedBy: .equal, - toItem: superview, + toItem: self, attribute: .top, multiplier: 1, constant: originY From 7a1809a4a9256f571c31e543c712ca973a0904e6 Mon Sep 17 00:00:00 2001 From: Roman Kyrylenko Date: Fri, 18 Aug 2017 16:00:48 +0300 Subject: [PATCH 09/13] Create contributing.md --- .github/contributing.md | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/contributing.md diff --git a/.github/contributing.md b/.github/contributing.md new file mode 100644 index 0000000..221c6cd --- /dev/null +++ b/.github/contributing.md @@ -0,0 +1,58 @@ +## How to contribute to Segmentio + +#### **Did you find a bug?** + +* **Ensure the bug was not already reported** by searching under [Issues](https://github.com/Yalantis/Segmentio/issues). + +* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/Yalantis/Segmentio/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **example project** demonstrating the expected behavior that is not occurring. + +* Fill appropriate section in issue template and remove the section you aren't interested in. + +#### **Did you write a patch that fixes a bug?** + +* Open a new GitHub pull request with the patch. + +* Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable. + +* Ensure the PR doesn't extend the number of existing issues. + +#### **Did you fix whitespace, format code, or make a purely cosmetic patch?** + +* Changes that are **cosmetic** in nature and **do not add anything substantial** to the stability or functionality of Segmentio will generally **not be accepted**. + +#### **Did you write patch that extends functionality?** + +* Ensure the functionality you trying to add needed not only for your case. + +#### Each issue will be labeled by it's `type`, `priority` and `status`. + +**Issue types:** +* Bug +* Enhancement + +**These are the available priority labels:** +* Critical +* High +* Medium +* Low + +**Status label will be assigned to your issue to keep the issue tracker easy to follow:** +* Queued (will be reviewed soon) +* Reviewed (assignee has read it) +* Pending (will work on it soon) +* Work in progress (is working on it now) +* On hold +* Invalid (if bug it's not reproducible) +* Need feedback (signal to get people to read and comment or provide help) + +#### **Coding Style** + +* Most importantly, match the existing code style as much as possible. + +#### **Do you have a question?** + +For any usage questions that are not specific to the project itself, please ask on [Stack Overflow](https://stackoverflow.com/). By doing so, you'll be more likely to quickly solve your problem, and you'll allow anyone else with the same question to find the answer. This also allows maintainers to focus on improving the project for others. + +## Thank you! + +#### [![Yalantis](https://raw.githubusercontent.com/Yalantis/PullToMakeSoup/master/PullToMakeSoupDemo/Resouces/badge_dark.png)](https://Yalantis.com/?utm_source=github) From f81702be301248d39a93e442cb20961c811c9251 Mon Sep 17 00:00:00 2001 From: Elias Tykhonkov Date: Fri, 1 Sep 2017 15:38:12 +0300 Subject: [PATCH 10/13] Update README.md fixed markdown --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 89702bb..2c72d8e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -##Segmentio +## Segmentio [![Platform](http://img.shields.io/badge/platform-iOS-blue.svg?style=flat)](https://cocoapods.org/?q=segmentio) [![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/Yalantis/Segmentio/blob/master/LICENSE) ![Swift 3.x](https://img.shields.io/badge/Swift-3.0-orange.svg) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) Animated top/bottom segmented control written in Swift. @@ -7,15 +7,15 @@ Animated top/bottom segmented control written in Swift. Check this project on dribbble. -##Requirements +## Requirements - Xcode 8 - iOS 8.x+ - Swift 3 -##Installation +## Installation -####[CocoaPods](http://cocoapods.org) +#### [CocoaPods](http://cocoapods.org) ```ruby use_frameworks! @@ -24,18 +24,18 @@ pod 'Segmentio', '~> 2.1' *CocoaPods v1.1.0 or later required* -####[Carthage](http://github.com/Carthage/Carthage) +#### [Carthage](http://github.com/Carthage/Carthage) ```ruby github "Yalantis/Segmentio" ~> 2.1 ``` -##Usage -####Import `Segmentio` module +## Usage +#### Import `Segmentio` module ```swift import Segmentio ``` -####Init +#### Init You can initialize a `Segmentio` instance from code: ```swift @@ -54,7 +54,7 @@ add a `UIView` instance in your .storyboard or .xib, set `Segmentio` class and c @IBOutlet weak var segmentioView: Segmentio! ``` -####Setup `Segmentio` +#### Setup `Segmentio` ```swift segmentioView.setup( content: [SegmentioItem], @@ -74,7 +74,7 @@ segmentioView.setup( ``` -####Configuring items +#### Configuring items In order to set items you need to create an array of `SegmentioItem` instances: ```swift @@ -87,14 +87,14 @@ let tornadoItem = SegmentioItem( content.append(tornadoItem) ``` -####Handling selection +#### Handling selection You can specify selected item manually: ```swift segmentioView.selectedSegmentioIndex = 0 ``` -####Handling callback +#### Handling callback ```swift segmentioView.valueDidChange = { segmentio, segmentIndex in @@ -102,7 +102,7 @@ segmentioView.valueDidChange = { segmentio, segmentIndex in } ``` -####Customization +#### Customization `Segmentio` can be customized by passing an instance of `SegmentioOptions` struct: ```swift @@ -171,12 +171,12 @@ SegmentioStates( ) ``` -####Let us know! +#### Let us know! We’d be really happy if you sent us links to your projects where you use our component. Just send an email to github@yalantis.com And do let us know if you have any questions or suggestion regarding the animation. P.S. We’re going to publish more awesomeness wrapped in code and a tutorial on how to make UI for iOS (Android) better than better. Stay tuned! -##License +## License The MIT License (MIT) From 72c4974a4393f8e74b08f2906a79646c370b9879 Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 1 Sep 2017 17:33:02 +0300 Subject: [PATCH 11/13] changes after review --- Segmentio/Source/Cells/SegmentioCell.swift | 2 +- Segmentio/Source/Segmentio.swift | 8 ++++++-- Segmentio/Source/SegmentioOptions.swift | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Segmentio/Source/Cells/SegmentioCell.swift b/Segmentio/Source/Cells/SegmentioCell.swift index 187e6fd..3b83d1f 100644 --- a/Segmentio/Source/Cells/SegmentioCell.swift +++ b/Segmentio/Source/Cells/SegmentioCell.swift @@ -130,7 +130,7 @@ class SegmentioCell: UICollectionViewCell { configurateBadgeWithCount(content.badgeCount, color: content.badgeColor) } - func configure(selected: Bool, selectedImage:UIImage? = nil, image:UIImage? = nil) { + func configure(selected: Bool, selectedImage: UIImage? = nil, image: UIImage? = nil) { cellSelected = selected let selectedState = options.states.selectedState diff --git a/Segmentio/Source/Segmentio.swift b/Segmentio/Source/Segmentio.swift index f4da738..74c5638 100644 --- a/Segmentio/Source/Segmentio.swift +++ b/Segmentio/Source/Segmentio.swift @@ -96,7 +96,7 @@ open class Segmentio: UIView { collectionView.bounces = true collectionView.isScrollEnabled = segmentioOptions.scrollEnabled collectionView.backgroundColor = .clear - collectionView.accessibilityIdentifier = "segmentio_collection_view" + collectionView.accessibilityIdentifier = "segmentio_collection_view" segmentioCollectionView = collectionView @@ -546,7 +546,11 @@ extension Segmentio: UICollectionViewDataSource { isLastCell: indexPath.row == segmentioItems.count - 1 ) - cell.configure(selected: (indexPath.row == selectedSegmentioIndex), selectedImage:content.selectedImage, image:content.image) + cell.configure( + selected: (indexPath.row == selectedSegmentioIndex), + selectedImage: content.selectedImage, + image: content.image + ) return cell } diff --git a/Segmentio/Source/SegmentioOptions.swift b/Segmentio/Source/SegmentioOptions.swift index 3addf9c..2ca66ca 100644 --- a/Segmentio/Source/SegmentioOptions.swift +++ b/Segmentio/Source/SegmentioOptions.swift @@ -21,7 +21,7 @@ public struct SegmentioItem { public init(title: String?, image: UIImage?, selectedImage: UIImage? = nil) { self.title = title self.image = image - self.selectedImage = selectedImage + self.selectedImage = selectedImage ?? image } public mutating func addBadge(_ count: Int, color: UIColor) { From 9805a5106cc7a20aa71e92a1fe385d2ff33e2601 Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 1 Sep 2017 18:51:14 +0300 Subject: [PATCH 12/13] remove instant backgounr color replacment --- Segmentio/Source/Cells/SegmentioCell.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Segmentio/Source/Cells/SegmentioCell.swift b/Segmentio/Source/Cells/SegmentioCell.swift index 3b83d1f..c370468 100644 --- a/Segmentio/Source/Cells/SegmentioCell.swift +++ b/Segmentio/Source/Cells/SegmentioCell.swift @@ -140,9 +140,7 @@ class SegmentioCell: UICollectionViewCell { segmentTitleLabel?.textColor = selected ? selectedState.titleTextColor : defaultState.titleTextColor segmentTitleLabel?.font = selected ? selectedState.titleFont : defaultState.titleFont } - - backgroundColor = selected ? selectedState.backgroundColor : defaultState.backgroundColor - + if (style != .onlyLabel) { segmentImageView?.image = selected ? selectedImage : image } From 7b8ca108d79785165cddc40ecdaf115214b92e6d Mon Sep 17 00:00:00 2001 From: Elias Tykhonkov Date: Sat, 2 Sep 2017 13:33:54 +0300 Subject: [PATCH 13/13] fix #39 --- Segmentio/Source/Cells/SegmentioCell.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Segmentio/Source/Cells/SegmentioCell.swift b/Segmentio/Source/Cells/SegmentioCell.swift index c370468..8cb4199 100644 --- a/Segmentio/Source/Cells/SegmentioCell.swift +++ b/Segmentio/Source/Cells/SegmentioCell.swift @@ -49,7 +49,7 @@ class SegmentioCell: UICollectionViewCell { segmentTitleLabel?.font = isHighlighted ? highlightedState.titleFont : highlightedTitleFont } - backgroundColor = isHighlighted ? highlightedState.backgroundColor : defaultState.backgroundColor + backgroundColor = isHighlighted ? highlightedState.backgroundColor : .clear } } }