Compare commits

..

No commits in common. "master" and "issues_fixes" have entirely different histories.

8 changed files with 83 additions and 87 deletions

View File

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

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright © 2017 Yalantis
Copyright © 2016 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

View File

@ -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.main.bounds.width, height: 125)
let segmentioViewRect = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().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.setup(
segmentioView.setupContent(
content: [SegmentioItem],
style: SegmentioStyle,
options: SegmentioOptions?
@ -66,7 +66,7 @@ segmentioView.setup(
To start with default options you can just pass `nil` to the `options` parameter.
```swift
segmentioView.setup(
segmentioView.setupContent(
content: [SegmentioItem],
style: SegmentioStyle,
options: nil
@ -91,7 +91,7 @@ content.append(tornadoItem)
You can specify selected item manually:
```swift
segmentioView.selectedSegmentioIndex = 0
segmentioView.selectedSegmentIndex = 0
```
####Handling callback
@ -107,15 +107,17 @@ segmentioView.valueDidChange = { segmentio, segmentIndex in
```swift
SegmentioOptions(
backgroundColor: .white,
maxVisibleItems: 3,
scrollEnabled: true,
indicatorOptions: SegmentioIndicatorOptions,
horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions,
verticalSeparatorOptions: SegmentioVerticalSeparatorOptions,
imageContentMode: .center,
labelTextAlignment: .center,
segmentStates: SegmentioStates
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
)
```
@ -123,10 +125,10 @@ Selection indicator can be customized by passing an instance of `SegmentioIndica
```swift
SegmentioIndicatorOptions(
type: .bottom,
ratio: 1,
height: 5,
color: .orange
type: .Bottom,
ratio: 1,
height: 5,
color: UIColor.orangeColor()
)
```
@ -134,9 +136,9 @@ Horizontal borders can be customized by passing an instance of `SegmentioHorizon
```swift
SegmentioHorizontalSeparatorOptions(
type: SegmentioHorizontalSeparatorType.topAndBottom, // Top, Bottom, TopAndBottom
height: 1,
color: .gray
type: SegmentioHorizontalSeparatorType.TopAndBottom, // Top, Bottom, TopAndBottom
height: 1,
color: UIColor.grayColor()
)
```
@ -144,8 +146,8 @@ Separators between segments can be customized by passing an instance of `Segmen
```swift
SegmentioVerticalSeparatorOptions(
ratio: 0.6, // from 0.1 to 1
color: .gray
ratio: 0.6 // from 0.1 to 1
color: UIColor.grayColor()
)
```
@ -153,21 +155,21 @@ In order to set `SegmentioStates` you need to create a tuple of `SegmentioState`
```swift
SegmentioStates(
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
)
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()
)
)
```
@ -180,7 +182,7 @@ P.S. Were going to publish more awesomeness wrapped in code and a tutorial on
The MIT License (MIT)
Copyright © 2017 Yalantis
Copyright © 2016 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

View File

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

View File

@ -173,43 +173,38 @@ class SegmentioCell: UICollectionViewCell {
// MARK: - Private functions
fileprivate func setupContainerConstraints() {
guard let segmentTitleLabel = segmentTitleLabel, let containerView = containerView else {
guard let segmentTitleLabel = segmentTitleLabel else {
return
}
guard let containerView = containerView else {
return
}
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: .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 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
)
addConstraints([
segmentTitleLabelTrailingConstraint,
segmentTitleLabelVerticalCenterConstraint,
segmentTitleLabelLeadingConstraint
])
segmentTitleLabelHorizontalCenterConstraint,
segmentTitleLabelVerticalCenterConstraint
])
}
fileprivate func setupImageContainerConstraints() {

View File

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

View File

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

View File

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