Compare commits
16 Commits
issues_fix
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
7473ff0b1d | |
|
|
8a21e29e89 | |
|
|
51f08913fb | |
|
|
8042192731 | |
|
|
80d911795c | |
|
|
e14c5c0b16 | |
|
|
cf3f6aaba0 | |
|
|
dd65378ed5 | |
|
|
05fb10bee7 | |
|
|
50ecb102e7 | |
|
|
6b542845f3 | |
|
|
06f6b0056b | |
|
|
13494d9f38 | |
|
|
790e466868 | |
|
|
715b851ca0 | |
|
|
a71ab5ecca |
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
2
LICENSE
2
LICENSE
|
|
@ -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
|
||||||
|
|
|
||||||
78
README.md
78
README.md
|
|
@ -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. We’re 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
|
||||||
|
|
|
||||||
|
|
@ -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!"
|
||||||
|
|
|
||||||
|
|
@ -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() {
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue