Add animationDuration and numberOfLines of segmentTitleLabel to SegmentioOptions. Update README.md.

This commit is contained in:
Edward Kobylyanets 2016-10-19 09:56:52 +03:00
parent 34cf755361
commit 2808a754eb
4 changed files with 13 additions and 6 deletions

View File

@ -114,8 +114,10 @@ SegmentioOptions(
horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions,
verticalSeparatorOptions: SegmentioVerticalSeparatorOptions,
imageContentMode: UIViewContentMode.Center,
labelTextNumberOfLines: 1,
labelTextAlignment: NSTextAlignment.Center,
segmentStates: SegmentioStates // tuple of SegmentioState (defaultState, selectState, highlightedState)
segmentStates: SegmentioStates, // tuple of SegmentioState (defaultState, selectState, highlightedState)
animationDuration: 0.1
)
```
@ -198,4 +200,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.

View File

@ -267,6 +267,7 @@ class SegmentioCell: UICollectionViewCell {
if style.isWithText() {
segmentTitleLabel?.textAlignment = options.labelTextAlignment
segmentTitleLabel?.numberOfLines = options.labelTextNumberOfLines
let defaultState = options.states.defaultState
segmentTitleLabel?.textColor = defaultState.titleTextColor
segmentTitleLabel?.font = defaultState.titleFont

View File

@ -11,8 +11,6 @@ import QuartzCore
public typealias SegmentioSelectionCallback = ((_ segmentio: Segmentio, _ selectedSegmentioIndex: Int) -> Void)
private let animationDuration: CFTimeInterval = 0.3
open class Segmentio: UIView {
internal struct Points {
@ -438,7 +436,7 @@ open class Segmentio: UIView {
let animation = CABasicAnimation(keyPath: "path")
animation.fromValue = shapeLayer.path
animation.toValue = shapeLayerPath.cgPath
animation.duration = animationDuration
animation.duration = segmentioOptions.animationDuration
CATransaction.setCompletionBlock() {
self.isPerformingScrollAnimation = false
self.isUserInteractionEnabled = true

View File

@ -162,7 +162,9 @@ public struct SegmentioOptions {
var indicatorOptions: SegmentioIndicatorOptions?
var imageContentMode: UIViewContentMode
var labelTextAlignment: NSTextAlignment
var labelTextNumberOfLines: Int
var states: SegmentioStates
var animationDuration: CFTimeInterval
public init() {
self.backgroundColor = .lightGray
@ -176,15 +178,17 @@ public struct SegmentioOptions {
self.imageContentMode = .center
self.labelTextAlignment = .center
self.labelTextNumberOfLines = 0
self.states = SegmentioStates(
defaultState: SegmentioState(),
selectedState: SegmentioState(),
highlightedState: SegmentioState()
)
self.animationDuration = 0.1
}
public init(backgroundColor: UIColor, maxVisibleItems: Int, scrollEnabled: Bool, indicatorOptions: SegmentioIndicatorOptions?, horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions?, verticalSeparatorOptions: SegmentioVerticalSeparatorOptions?, imageContentMode: UIViewContentMode, labelTextAlignment: NSTextAlignment, segmentStates: SegmentioStates) {
public init(backgroundColor: UIColor, maxVisibleItems: Int, scrollEnabled: Bool, indicatorOptions: SegmentioIndicatorOptions?, horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions?, verticalSeparatorOptions: SegmentioVerticalSeparatorOptions?, imageContentMode: UIViewContentMode, labelTextAlignment: NSTextAlignment, labelTextNumberOfLines: Int, segmentStates: SegmentioStates, animationDuration: CFTimeInterval) {
self.backgroundColor = backgroundColor
self.maxVisibleItems = maxVisibleItems
self.scrollEnabled = scrollEnabled
@ -193,7 +197,9 @@ public struct SegmentioOptions {
self.verticalSeparatorOptions = verticalSeparatorOptions
self.imageContentMode = imageContentMode
self.labelTextAlignment = labelTextAlignment
self.labelTextNumberOfLines = labelTextNumberOfLines
self.states = segmentStates
self.animationDuration = animationDuration
}
}