Skip to content

Commit

Permalink
Merge pull request Yalantis#36 from piechart/master
Browse files Browse the repository at this point in the history
Code examples updated to Swift 3 syntax
  • Loading branch information
serejahh authored Dec 21, 2016
2 parents cf3f6aa + e14c5c0 commit 80d9117
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
Expand All @@ -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?
Expand All @@ -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
Expand All @@ -91,7 +91,7 @@ content.append(tornadoItem)
You can specify selected item manually:

```swift
segmentioView.selectedSegmentIndex = 0
segmentioView.selectedSegmentioIndex = 0
```

####Handling callback
Expand All @@ -107,69 +107,67 @@ 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
)
```

Selection indicator can be customized by passing an instance of `SegmentioIndicatorOptions`:

```swift
SegmentioIndicatorOptions(
type: .Bottom,
ratio: 1,
height: 5,
color: UIColor.orangeColor()
type: .bottom,
ratio: 1,
height: 5,
color: .orange
)
```

Horizontal borders can be customized by passing an instance of `SegmentioHorizontalSeparatorOptions`:

```swift
SegmentioHorizontalSeparatorOptions(
type: SegmentioHorizontalSeparatorType.TopAndBottom, // Top, Bottom, TopAndBottom
height: 1,
color: UIColor.grayColor()
type: SegmentioHorizontalSeparatorType.topAndBottom, // Top, Bottom, TopAndBottom
height: 1,
color: .gray
)
```

Separators between segments can be customized by passing an instance of `SegmentioVerticalSeparatorOptions`:

```swift
SegmentioVerticalSeparatorOptions(
ratio: 0.6 // from 0.1 to 1
color: UIColor.grayColor()
ratio: 0.6, // from 0.1 to 1
color: .gray
)
```

In order to set `SegmentioStates` you need to create a tuple of `SegmentioState` instances:

```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
)
)
```

Expand Down

0 comments on commit 80d9117

Please sign in to comment.