From 2808a754eb35c82658ddfdf82667e3f91fa2a6a5 Mon Sep 17 00:00:00 2001 From: Edward Kobylyanets Date: Wed, 19 Oct 2016 09:56:52 +0300 Subject: [PATCH] Add animationDuration and numberOfLines of segmentTitleLabel to SegmentioOptions. Update README.md. --- README.md | 6 ++++-- Segmentio/Source/Cells/SegmentioCell.swift | 1 + Segmentio/Source/Segmentio.swift | 4 +--- Segmentio/Source/SegmentioOptions.swift | 8 +++++++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b8b5c28..2f66632 100644 --- a/README.md +++ b/README.md @@ -114,8 +114,10 @@ SegmentioOptions( horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions, verticalSeparatorOptions: SegmentioVerticalSeparatorOptions, imageContentMode: UIViewContentMode.Center, + labelTextNumberOfLines: 1, labelTextAlignment: NSTextAlignment.Center, - segmentStates: SegmentioStates // tuple of SegmentioState (defaultState, selectState, highlightedState) + segmentStates: SegmentioStates, // tuple of SegmentioState (defaultState, selectState, highlightedState) + animationDuration: 0.1 ) ``` @@ -198,4 +200,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. diff --git a/Segmentio/Source/Cells/SegmentioCell.swift b/Segmentio/Source/Cells/SegmentioCell.swift index de9ef89..27f369b 100644 --- a/Segmentio/Source/Cells/SegmentioCell.swift +++ b/Segmentio/Source/Cells/SegmentioCell.swift @@ -267,6 +267,7 @@ class SegmentioCell: UICollectionViewCell { if style.isWithText() { segmentTitleLabel?.textAlignment = options.labelTextAlignment + segmentTitleLabel?.numberOfLines = options.labelTextNumberOfLines let defaultState = options.states.defaultState segmentTitleLabel?.textColor = defaultState.titleTextColor segmentTitleLabel?.font = defaultState.titleFont diff --git a/Segmentio/Source/Segmentio.swift b/Segmentio/Source/Segmentio.swift index c3c3522..cbf4742 100644 --- a/Segmentio/Source/Segmentio.swift +++ b/Segmentio/Source/Segmentio.swift @@ -11,8 +11,6 @@ import QuartzCore public typealias SegmentioSelectionCallback = ((_ segmentio: Segmentio, _ selectedSegmentioIndex: Int) -> Void) -private let animationDuration: CFTimeInterval = 0.3 - open class Segmentio: UIView { internal struct Points { @@ -438,7 +436,7 @@ open class Segmentio: UIView { let animation = CABasicAnimation(keyPath: "path") animation.fromValue = shapeLayer.path animation.toValue = shapeLayerPath.cgPath - animation.duration = animationDuration + animation.duration = segmentioOptions.animationDuration CATransaction.setCompletionBlock() { self.isPerformingScrollAnimation = false self.isUserInteractionEnabled = true diff --git a/Segmentio/Source/SegmentioOptions.swift b/Segmentio/Source/SegmentioOptions.swift index 57ddb0a..14528d8 100644 --- a/Segmentio/Source/SegmentioOptions.swift +++ b/Segmentio/Source/SegmentioOptions.swift @@ -162,7 +162,9 @@ public struct SegmentioOptions { var indicatorOptions: SegmentioIndicatorOptions? var imageContentMode: UIViewContentMode var labelTextAlignment: NSTextAlignment + var labelTextNumberOfLines: Int var states: SegmentioStates + var animationDuration: CFTimeInterval public init() { self.backgroundColor = .lightGray @@ -176,15 +178,17 @@ public struct SegmentioOptions { self.imageContentMode = .center self.labelTextAlignment = .center + self.labelTextNumberOfLines = 0 self.states = SegmentioStates( defaultState: SegmentioState(), selectedState: SegmentioState(), highlightedState: SegmentioState() ) + self.animationDuration = 0.1 } - public init(backgroundColor: UIColor, maxVisibleItems: Int, scrollEnabled: Bool, indicatorOptions: SegmentioIndicatorOptions?, horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions?, verticalSeparatorOptions: SegmentioVerticalSeparatorOptions?, imageContentMode: UIViewContentMode, labelTextAlignment: NSTextAlignment, segmentStates: SegmentioStates) { + public init(backgroundColor: UIColor, maxVisibleItems: Int, scrollEnabled: Bool, indicatorOptions: SegmentioIndicatorOptions?, horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions?, verticalSeparatorOptions: SegmentioVerticalSeparatorOptions?, imageContentMode: UIViewContentMode, labelTextAlignment: NSTextAlignment, labelTextNumberOfLines: Int, segmentStates: SegmentioStates, animationDuration: CFTimeInterval) { self.backgroundColor = backgroundColor self.maxVisibleItems = maxVisibleItems self.scrollEnabled = scrollEnabled @@ -193,7 +197,9 @@ public struct SegmentioOptions { self.verticalSeparatorOptions = verticalSeparatorOptions self.imageContentMode = imageContentMode self.labelTextAlignment = labelTextAlignment + self.labelTextNumberOfLines = labelTextNumberOfLines self.states = segmentStates + self.animationDuration = animationDuration } }