Compare commits
No commits in common. "master" and "issues_fixes" have entirely different histories.
master
...
issues_fix
|
|
@ -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 © 2017 Yalantis
|
Copyright © 2016 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.main.bounds.width, height: 125)
|
let segmentioViewRect = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().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.setup(
|
segmentioView.setupContent(
|
||||||
content: [SegmentioItem],
|
content: [SegmentioItem],
|
||||||
style: SegmentioStyle,
|
style: SegmentioStyle,
|
||||||
options: SegmentioOptions?
|
options: SegmentioOptions?
|
||||||
|
|
@ -66,7 +66,7 @@ segmentioView.setup(
|
||||||
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.setup(
|
segmentioView.setupContent(
|
||||||
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.selectedSegmentioIndex = 0
|
segmentioView.selectedSegmentIndex = 0
|
||||||
```
|
```
|
||||||
|
|
||||||
####Handling callback
|
####Handling callback
|
||||||
|
|
@ -107,15 +107,17 @@ segmentioView.valueDidChange = { segmentio, segmentIndex in
|
||||||
|
|
||||||
```swift
|
```swift
|
||||||
SegmentioOptions(
|
SegmentioOptions(
|
||||||
backgroundColor: .white,
|
backgroundColor: UIColor.whiteColor(),
|
||||||
maxVisibleItems: 3,
|
maxVisibleItems: 3,
|
||||||
scrollEnabled: true,
|
scrollEnabled: true,
|
||||||
indicatorOptions: SegmentioIndicatorOptions,
|
indicatorOptions: SegmentioIndicatorOptions,
|
||||||
horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions,
|
horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions,
|
||||||
verticalSeparatorOptions: SegmentioVerticalSeparatorOptions,
|
verticalSeparatorOptions: SegmentioVerticalSeparatorOptions,
|
||||||
imageContentMode: .center,
|
imageContentMode: UIViewContentMode.Center,
|
||||||
labelTextAlignment: .center,
|
labelTextNumberOfLines: 1,
|
||||||
segmentStates: SegmentioStates
|
labelTextAlignment: NSTextAlignment.Center,
|
||||||
|
segmentStates: SegmentioStates, // tuple of SegmentioState (defaultState, selectState, highlightedState)
|
||||||
|
animationDuration: 0.1
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -123,10 +125,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: .orange
|
color: UIColor.orangeColor()
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -134,9 +136,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: .gray
|
color: UIColor.grayColor()
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -144,8 +146,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: .gray
|
color: UIColor.grayColor()
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -153,21 +155,21 @@ In order to set `SegmentioStates` you need to create a tuple of `SegmentioState`
|
||||||
|
|
||||||
```swift
|
```swift
|
||||||
SegmentioStates(
|
SegmentioStates(
|
||||||
defaultState: SegmentioState(
|
defaultState: segmentioState(
|
||||||
backgroundColor: .clear,
|
backgroundColor: UIColor.clearColor(),
|
||||||
titleFont: UIFont.systemFont(ofSize: UIFont.smallSystemFontSize),
|
titleFont: UIFont.systemFontOfSize(UIFont.smallSystemFontSize()),
|
||||||
titleTextColor: .black
|
titleTextColor: UIColor.blackColor()
|
||||||
),
|
),
|
||||||
selectedState: SegmentioState(
|
selectState: segmentioState(
|
||||||
backgroundColor: .orange,
|
backgroundColor: UIColor.orangeColor(),
|
||||||
titleFont: UIFont.systemFont(ofSize: UIFont.smallSystemFontSize),
|
titleFont: UIFont.systemFontOfSize(UIFont.smallSystemFontSize()),
|
||||||
titleTextColor: .white
|
titleTextColor: UIColor.whiteColor()
|
||||||
),
|
),
|
||||||
highlightedState: SegmentioState(
|
highlightedState: segmentioState(
|
||||||
backgroundColor: UIColor.lightGray.withAlphaComponent(0.6),
|
backgroundColor: UIColor.lightGrayColor().colorWithAlphaComponent(0.6),
|
||||||
titleFont: UIFont.boldSystemFont(ofSize: UIFont.smallSystemFontSize),
|
titleFont: UIFont.boldSystemFontOfSize(UIFont.smallSystemFontSize()),
|
||||||
titleTextColor: .black
|
titleTextColor: UIColor.blackColor()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -180,7 +182,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 © 2017 Yalantis
|
Copyright © 2016 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.1.2"
|
spec.version = "2.0"
|
||||||
|
|
||||||
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,43 +173,38 @@ class SegmentioCell: UICollectionViewCell {
|
||||||
// MARK: - Private functions
|
// MARK: - Private functions
|
||||||
|
|
||||||
fileprivate func setupContainerConstraints() {
|
fileprivate func setupContainerConstraints() {
|
||||||
guard let segmentTitleLabel = segmentTitleLabel, let containerView = containerView else {
|
guard let segmentTitleLabel = segmentTitleLabel else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard let containerView = containerView else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let segmentTitleLabelVerticalCenterConstraint = NSLayoutConstraint(
|
let segmentTitleLabelHorizontalCenterConstraint =
|
||||||
item: segmentTitleLabel,
|
NSLayoutConstraint(
|
||||||
attribute: .centerY,
|
item: segmentTitleLabel,
|
||||||
relatedBy: .equal,
|
attribute: .centerX,
|
||||||
toItem: containerView,
|
relatedBy: .equal,
|
||||||
attribute: .centerY,
|
toItem: containerView,
|
||||||
multiplier: 1,
|
attribute: .centerX,
|
||||||
constant: 0
|
multiplier: 1,
|
||||||
)
|
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([
|
||||||
segmentTitleLabelTrailingConstraint,
|
segmentTitleLabelHorizontalCenterConstraint,
|
||||||
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]|", //changed from |-[containerView]-|. remove standard space
|
withVisualFormat: "|-[containerView]-|",
|
||||||
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,7 +323,6 @@ 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 {
|
||||||
|
|
||||||
public var title: String?
|
var title: String?
|
||||||
public var image: UIImage?
|
var image: UIImage?
|
||||||
public var badgeCount: Int?
|
var badgeCount: Int?
|
||||||
public var badgeColor: UIColor?
|
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