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

View File

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

View File

@ -22,7 +22,7 @@ final class SegmentioCellWithLabel: SegmentioCell {
// main constraints
let segmentTitleLabelHorizontConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "|-[containerView]-|",
withVisualFormat: "|[containerView]|", //changed from |-[containerView]-|. remove standard space
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,6 +323,7 @@ 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 {
var title: String?
var image: UIImage?
var badgeCount: Int?
var badgeColor: UIColor?
public var title: String?
public var image: UIImage?
public var badgeCount: Int?
public var badgeColor: UIColor?
public init(title: String?, image: UIImage?) {
self.title = title
self.image = image