Compare commits

..

16 Commits

Author SHA1 Message Date
Igor Kislyuk 7473ff0b1d Fix. Add more space for label 2017-03-30 17:53:14 +03:00
Serhii Butenko 8a21e29e89 Fix word overbounds (closes #16) 2017-01-17 08:46:08 +02:00
Boris Vinogradov 51f08913fb Update README.md 2017-01-13 12:42:25 +02:00
Boris Vinogradov 8042192731 Update LICENSE 2017-01-13 12:42:00 +02:00
Serhii Butenko 80d911795c Merge pull request #36 from piechart/master
Code examples updated to Swift 3 syntax
2016-12-21 22:52:05 +02:00
Michael Galperin e14c5c0b16 Code examples updated to Swift 3 2016-12-21 23:44:54 +03:00
Serhii Butenko cf3f6aaba0 Merge pull request #32 from maxcampolo/fix/reload
Fix/reload
2016-12-09 18:20:55 +02:00
Serhii Butenko dd65378ed5 Merge pull request #30 from maxcampolo/dev
SegmentioItem public getters
2016-12-09 18:20:28 +02:00
Max Campolo 05fb10bee7 Reload collection view in reloadSegmentio method 2016-12-09 10:49:16 -05:00
Max Campolo 50ecb102e7 Remove private setter 2016-12-06 09:22:06 -05:00
Max Campolo 6b542845f3 Make getter public for SegmentioItem variables 2016-12-05 11:47:17 -05:00
Serhii Butenko 06f6b0056b Merge pull request #29 from Yalantis/feature/28
Feature/28
2016-12-01 14:52:43 +02:00
Serhii Butenko 13494d9f38
Bump version 2016-12-01 14:52:09 +02:00
Serhii Butenko 790e466868
Make items property public 2016-12-01 14:51:46 +02:00
Serhii Butenko 715b851ca0 Update ISSUE_TEMPLATE.md 2016-11-24 13:29:01 +02:00
Dmitriy Demchenko a71ab5ecca [Update] Segmentio.podspec 2016-11-24 12:29:38 +02:00
8 changed files with 87 additions and 83 deletions

View File

@ -30,13 +30,13 @@
### Your Environment ### Your Environment
- [ ] Version of the component: _insert here_ - Version of the component: _insert here_
- [ ] Swift version: _insert here_ - Swift version: _insert here_
- [ ] iOS version: _insert here_ - iOS version: _insert here_
- [ ] Device: _insert here_ - Device: _insert here_
- [ ] Xcode version: _insert here_ - Xcode version: _insert here_
- [ ] If you use Cocoapods: _run `pod env | pbcopy` and insert here_ - If you use Cocoapods: _run `pod env | pbcopy` and insert here_
- [ ] If you use Carthage: _run `carthage version | pbcopy` and insert here_ - If you use Carthage: _run `carthage version | pbcopy` and insert here_
### Project that demonstrates the bug ### Project that demonstrates the bug

View File

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright © 2016 Yalantis Copyright © 2017 Yalantis
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -41,7 +41,7 @@ You can initialize a `Segmentio` instance from code:
```swift ```swift
var segmentioView: Segmentio! 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) segmentioView = Segmentio(frame: segmentioViewRect)
view.addSubview(segmentioView) view.addSubview(segmentioView)
``` ```
@ -56,7 +56,7 @@ add a `UIView` instance in your .storyboard or .xib, set `Segmentio` class and c
####Setup `Segmentio` ####Setup `Segmentio`
```swift ```swift
segmentioView.setupContent( segmentioView.setup(
content: [SegmentioItem], content: [SegmentioItem],
style: SegmentioStyle, style: SegmentioStyle,
options: SegmentioOptions? options: SegmentioOptions?
@ -66,7 +66,7 @@ segmentioView.setupContent(
To start with default options you can just pass `nil` to the `options` parameter. To start with default options you can just pass `nil` to the `options` parameter.
```swift ```swift
segmentioView.setupContent( segmentioView.setup(
content: [SegmentioItem], content: [SegmentioItem],
style: SegmentioStyle, style: SegmentioStyle,
options: nil options: nil
@ -91,7 +91,7 @@ content.append(tornadoItem)
You can specify selected item manually: You can specify selected item manually:
```swift ```swift
segmentioView.selectedSegmentIndex = 0 segmentioView.selectedSegmentioIndex = 0
``` ```
####Handling callback ####Handling callback
@ -107,17 +107,15 @@ segmentioView.valueDidChange = { segmentio, segmentIndex in
```swift ```swift
SegmentioOptions( SegmentioOptions(
backgroundColor: UIColor.whiteColor(), backgroundColor: .white,
maxVisibleItems: 3, maxVisibleItems: 3,
scrollEnabled: true, scrollEnabled: true,
indicatorOptions: SegmentioIndicatorOptions, indicatorOptions: SegmentioIndicatorOptions,
horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions, horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions,
verticalSeparatorOptions: SegmentioVerticalSeparatorOptions, verticalSeparatorOptions: SegmentioVerticalSeparatorOptions,
imageContentMode: UIViewContentMode.Center, imageContentMode: .center,
labelTextNumberOfLines: 1, labelTextAlignment: .center,
labelTextAlignment: NSTextAlignment.Center, segmentStates: SegmentioStates
segmentStates: SegmentioStates, // tuple of SegmentioState (defaultState, selectState, highlightedState)
animationDuration: 0.1
) )
``` ```
@ -125,10 +123,10 @@ Selection indicator can be customized by passing an instance of `SegmentioIndica
```swift ```swift
SegmentioIndicatorOptions( SegmentioIndicatorOptions(
type: .Bottom, type: .bottom,
ratio: 1, ratio: 1,
height: 5, height: 5,
color: UIColor.orangeColor() color: .orange
) )
``` ```
@ -136,9 +134,9 @@ Horizontal borders can be customized by passing an instance of `SegmentioHorizon
```swift ```swift
SegmentioHorizontalSeparatorOptions( SegmentioHorizontalSeparatorOptions(
type: SegmentioHorizontalSeparatorType.TopAndBottom, // Top, Bottom, TopAndBottom type: SegmentioHorizontalSeparatorType.topAndBottom, // Top, Bottom, TopAndBottom
height: 1, height: 1,
color: UIColor.grayColor() color: .gray
) )
``` ```
@ -146,8 +144,8 @@ Separators between segments can be customized by passing an instance of `Segmen
```swift ```swift
SegmentioVerticalSeparatorOptions( SegmentioVerticalSeparatorOptions(
ratio: 0.6 // from 0.1 to 1 ratio: 0.6, // from 0.1 to 1
color: UIColor.grayColor() color: .gray
) )
``` ```
@ -155,21 +153,21 @@ In order to set `SegmentioStates` you need to create a tuple of `SegmentioState`
```swift ```swift
SegmentioStates( SegmentioStates(
defaultState: segmentioState( defaultState: SegmentioState(
backgroundColor: UIColor.clearColor(), backgroundColor: .clear,
titleFont: UIFont.systemFontOfSize(UIFont.smallSystemFontSize()), titleFont: UIFont.systemFont(ofSize: UIFont.smallSystemFontSize),
titleTextColor: UIColor.blackColor() titleTextColor: .black
), ),
selectState: segmentioState( selectedState: SegmentioState(
backgroundColor: UIColor.orangeColor(), backgroundColor: .orange,
titleFont: UIFont.systemFontOfSize(UIFont.smallSystemFontSize()), titleFont: UIFont.systemFont(ofSize: UIFont.smallSystemFontSize),
titleTextColor: UIColor.whiteColor() titleTextColor: .white
), ),
highlightedState: segmentioState( highlightedState: SegmentioState(
backgroundColor: UIColor.lightGrayColor().colorWithAlphaComponent(0.6), backgroundColor: UIColor.lightGray.withAlphaComponent(0.6),
titleFont: UIFont.boldSystemFontOfSize(UIFont.smallSystemFontSize()), titleFont: UIFont.boldSystemFont(ofSize: UIFont.smallSystemFontSize),
titleTextColor: UIColor.blackColor() titleTextColor: .black
) )
) )
``` ```
@ -182,7 +180,7 @@ P.S. Were going to publish more awesomeness wrapped in code and a tutorial on
The MIT License (MIT) The MIT License (MIT)
Copyright © 2016 Yalantis Copyright © 2017 Yalantis
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |spec| Pod::Spec.new do |spec|
spec.name = "Segmentio" spec.name = "Segmentio"
spec.version = "2.0" spec.version = "2.1.2"
spec.homepage = "https://github.com/Yalantis/Segmentio" spec.homepage = "https://github.com/Yalantis/Segmentio"
spec.summary = "Animated top/bottom segmented control written in Swift!" spec.summary = "Animated top/bottom segmented control written in Swift!"

View File

@ -173,38 +173,43 @@ class SegmentioCell: UICollectionViewCell {
// MARK: - Private functions // MARK: - Private functions
fileprivate func setupContainerConstraints() { fileprivate func setupContainerConstraints() {
guard let segmentTitleLabel = segmentTitleLabel else { guard let segmentTitleLabel = segmentTitleLabel, let containerView = containerView else {
return
}
guard let containerView = containerView else {
return return
} }
let segmentTitleLabelHorizontalCenterConstraint = let segmentTitleLabelVerticalCenterConstraint = NSLayoutConstraint(
NSLayoutConstraint( item: segmentTitleLabel,
item: segmentTitleLabel, attribute: .centerY,
attribute: .centerX, relatedBy: .equal,
relatedBy: .equal, toItem: containerView,
toItem: containerView, attribute: .centerY,
attribute: .centerX, multiplier: 1,
multiplier: 1, constant: 0
constant: 0 )
let segmentTitleLabelTrailingConstraint = NSLayoutConstraint(
item: segmentTitleLabel,
attribute: .trailing,
relatedBy: .equal,
toItem: containerView,
attribute: .trailing, //changed from .trailingMargin. remove std margin 8pt
multiplier: 1.0,
constant: 0
)
let segmentTitleLabelLeadingConstraint = NSLayoutConstraint(
item: segmentTitleLabel,
attribute: .leading,
relatedBy: .equal,
toItem: containerView,
attribute: .leading, //changed from .leadingMargin. remove std margin 8pt
multiplier: 1.0,
constant: 0
) )
let segmentTitleLabelVerticalCenterConstraint =
NSLayoutConstraint(
item: segmentTitleLabel,
attribute: .centerY,
relatedBy: .equal,
toItem: containerView,
attribute: .centerY,
multiplier: 1,
constant: 0
)
addConstraints([ addConstraints([
segmentTitleLabelHorizontalCenterConstraint, segmentTitleLabelTrailingConstraint,
segmentTitleLabelVerticalCenterConstraint segmentTitleLabelVerticalCenterConstraint,
]) segmentTitleLabelLeadingConstraint
])
} }
fileprivate func setupImageContainerConstraints() { fileprivate func setupImageContainerConstraints() {

View File

@ -22,7 +22,7 @@ final class SegmentioCellWithLabel: SegmentioCell {
// main constraints // main constraints
let segmentTitleLabelHorizontConstraint = NSLayoutConstraint.constraints( let segmentTitleLabelHorizontConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "|-[containerView]-|", withVisualFormat: "|[containerView]|", //changed from |-[containerView]-|. remove standard space
options: [.alignAllCenterX], options: [.alignAllCenterX],
metrics: nil, metrics: nil,
views: views views: views

View File

@ -43,9 +43,9 @@ open class Segmentio: UIView {
} }
} }
} }
open fileprivate(set) var segmentioItems = [SegmentioItem]()
fileprivate var segmentioCollectionView: UICollectionView? fileprivate var segmentioCollectionView: UICollectionView?
fileprivate var segmentioItems = [SegmentioItem]()
fileprivate var segmentioOptions = SegmentioOptions() fileprivate var segmentioOptions = SegmentioOptions()
fileprivate var segmentioStyle = SegmentioStyle.imageOverLabel fileprivate var segmentioStyle = SegmentioStyle.imageOverLabel
fileprivate var isPerformingScrollAnimation = false fileprivate var isPerformingScrollAnimation = false
@ -323,6 +323,7 @@ open class Segmentio: UIView {
// MARK: Reload segmentio // MARK: Reload segmentio
public func reloadSegmentio() { public func reloadSegmentio() {
segmentioCollectionView?.collectionViewLayout.invalidateLayout() segmentioCollectionView?.collectionViewLayout.invalidateLayout()
segmentioCollectionView?.reloadData()
scrollToItemAtContext() scrollToItemAtContext()
moveShapeLayerAtContext() moveShapeLayerAtContext()
} }

View File

@ -12,11 +12,11 @@ import UIKit
public struct SegmentioItem { public struct SegmentioItem {
var title: String? public var title: String?
var image: UIImage? public var image: UIImage?
var badgeCount: Int? public var badgeCount: Int?
var badgeColor: UIColor? public var badgeColor: UIColor?
public init(title: String?, image: UIImage?) { public init(title: String?, image: UIImage?) {
self.title = title self.title = title
self.image = image self.image = image