Compare commits

...

27 Commits
2.0 ... master

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
Dmitriy Demchenko 75aa08272e [Update] Carthage: info.plist, project.pbxproj 2016-11-24 12:20:05 +02:00
Dmitriy Demchenko 73e1dd3402 [Update] plist.info 2016-11-24 12:17:03 +02:00
Dmitriy Demchenko fab49af07c [Update] project.pbxproj, Segmentio-Example.xcscheme 2016-11-24 12:15:46 +02:00
Dmitriy Demchenko eeda04fffb [Update] README.md 2016-11-24 12:14:08 +02:00
Dmitriy Demchenko 07f7d884fc [Add] SegmentioBuilder
[Update] ExampleViewController: moved setup segmentioView logic to SegmentioBuilder
[Fix] Autolayout issue using Segmentio programtically
[Update] SegmentioItem, SegmentioCell: minor updates
2016-11-14 13:07:54 +02:00
Dmitriy Demchenko e85b4ccb95 [Update] LICENSE file
[Add] ExampleViewController: overrided viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
[Add] Segmentio: added function interfaceOrientationDidChange
[Remove] Segmentio: removed var cachedOrientation
2016-11-11 17:05:00 +02:00
Dmitriy Demchenko f93e6be578 [Update] LaunchScreen.storyboard: updated constraints for Xcode 8
[Update] Main.storyboard: updated constraints for Xcode 8
[Fix] ExampleViewController: fixed segmentioOptions function
2016-11-09 13:22:34 +02:00
Igor Muzyka a97be5838e Merge pull request #17 from IgorMuzyka/master
Fixes issue #1
2016-11-07 16:55:53 +02:00
Igor Muzyka ac9cf49b69 Fixes issue #1 2016-11-07 16:55:21 +02:00
Igor Muzyka 848dfe4d32 Merge pull request #13 from kobylyanets/master
Added animationDuration and numberOfLines of segmentTitleLabel to SegmentioOptions.
2016-11-07 16:52:00 +02:00
Edward Kobylyanets 2808a754eb Add animationDuration and numberOfLines of segmentTitleLabel to SegmentioOptions. Update README.md. 2016-10-19 09:56:52 +03:00
17 changed files with 367 additions and 280 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

@ -24,6 +24,7 @@
327AF5EA1D1ABEC100534355 /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 327AF5CB1D1ABEC100534355 /* HomeViewController.swift */; };
327AF5EB1D1ABEC100534355 /* SideMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 327AF5CC1D1ABEC100534355 /* SideMenuViewController.swift */; };
327AF6041D1AC0FE00534355 /* ColorPalette.swift in Sources */ = {isa = PBXBuildFile; fileRef = 327AF6031D1AC0FE00534355 /* ColorPalette.swift */; };
32C3706C1DD9C4FA001A39CB /* SegmentioBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C3706B1DD9C4FA001A39CB /* SegmentioBuilder.swift */; };
5B9491B14F42A77448746E9B /* Pods_Segmentio_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 74E8553D39ECFE4883F1D2CA /* Pods_Segmentio_Example.framework */; };
/* End PBXBuildFile section */
@ -49,6 +50,7 @@
327AF5CB1D1ABEC100534355 /* HomeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HomeViewController.swift; sourceTree = "<group>"; };
327AF5CC1D1ABEC100534355 /* SideMenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideMenuViewController.swift; sourceTree = "<group>"; };
327AF6031D1AC0FE00534355 /* ColorPalette.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorPalette.swift; sourceTree = "<group>"; };
32C3706B1DD9C4FA001A39CB /* SegmentioBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SegmentioBuilder.swift; sourceTree = "<group>"; };
32C3A9241D2BB3B5004C0FC9 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
607FACD01AFB9204008FA782 /* Segmentio_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Segmentio_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -136,6 +138,14 @@
path = ViewControllers;
sourceTree = "<group>";
};
32C3706A1DD9C4EC001A39CB /* Builders */ = {
isa = PBXGroup;
children = (
32C3706B1DD9C4FA001A39CB /* SegmentioBuilder.swift */,
);
path = Builders;
sourceTree = "<group>";
};
45CA913E13914443DB2552B6 /* Pods */ = {
isa = PBXGroup;
children = (
@ -169,6 +179,7 @@
607FACD21AFB9204008FA782 /* Example for Segmentio */ = {
isa = PBXGroup;
children = (
32C3706A1DD9C4EC001A39CB /* Builders */,
327AF5A71D1ABEC100534355 /* Application */,
327AF5A91D1ABEC100534355 /* Extensions */,
327AF5AD1D1ABEC100534355 /* Helpers */,
@ -239,7 +250,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0810;
ORGANIZATIONNAME = CocoaPods;
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
@ -337,6 +348,7 @@
327AF5CF1D1ABEC100534355 /* AppDelegate.swift in Sources */,
327AF5EB1D1ABEC100534355 /* SideMenuViewController.swift in Sources */,
327AF5E81D1ABEC100534355 /* EmbedContainerViewController.swift in Sources */,
32C3706C1DD9C4FA001A39CB /* SegmentioBuilder.swift in Sources */,
327AF5D41D1ABEC100534355 /* Disaster.swift in Sources */,
327AF5D31D1ABEC100534355 /* AppearanceConfigurator.swift in Sources */,
327AF5EA1D1ABEC100534355 /* HomeViewController.swift in Sources */,
@ -365,8 +377,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@ -410,8 +424,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@ -430,6 +446,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
@ -438,6 +455,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 031FB43EDAB25B02B2FB7406 /* Pods-Segmentio_Example.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "";
FRAMEWORK_SEARCH_PATHS = (
@ -460,6 +478,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 1667ACAF5594F75E244C8E1B /* Pods-Segmentio_Example.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

View File

@ -0,0 +1,118 @@
//
// SegmentioBuilder.swift
// Segmentio
//
// Created by Dmitriy Demchenko on 11/14/16.
// Copyright © 2016 CocoaPods. All rights reserved.
//
import Segmentio
import UIKit
struct SegmentioBuilder {
static func setupBadgeCountForIndex(_ segmentioView: Segmentio, index: Int) {
segmentioView.addBadge(
at: index,
count: 10,
color: ColorPalette.coral
)
}
static func buildSegmentioView(segmentioView: Segmentio, segmentioStyle: SegmentioStyle) {
segmentioView.setup(
content: segmentioContent(),
style: segmentioStyle,
options: segmentioOptions(segmentioStyle: segmentioStyle)
)
}
private static func segmentioContent() -> [SegmentioItem] {
return [
SegmentioItem(title: "Tornado", image: UIImage(named: "tornado")),
SegmentioItem(title: "Earthquakes", image: UIImage(named: "earthquakes")),
SegmentioItem(title: "Extreme heat", image: UIImage(named: "heat")),
SegmentioItem(title: "Eruption", image: UIImage(named: "eruption")),
SegmentioItem(title: "Floods", image: UIImage(named: "floods")),
SegmentioItem(title: "Wildfires", image: UIImage(named: "wildfires"))
]
}
private static func segmentioOptions(segmentioStyle: SegmentioStyle) -> SegmentioOptions {
var imageContentMode = UIViewContentMode.center
switch segmentioStyle {
case .imageBeforeLabel, .imageAfterLabel:
imageContentMode = .scaleAspectFit
default:
break
}
return SegmentioOptions(
backgroundColor: ColorPalette.white,
maxVisibleItems: 3,
scrollEnabled: true,
indicatorOptions: segmentioIndicatorOptions(),
horizontalSeparatorOptions: segmentioHorizontalSeparatorOptions(),
verticalSeparatorOptions: segmentioVerticalSeparatorOptions(),
imageContentMode: imageContentMode,
labelTextAlignment: .center,
labelTextNumberOfLines: 1,
segmentStates: segmentioStates(),
animationDuration: 0.3
)
}
private static func segmentioStates() -> SegmentioStates {
let font = UIFont.exampleAvenirMedium(ofSize: 13)
return SegmentioStates(
defaultState: segmentioState(
backgroundColor: .clear,
titleFont: font,
titleTextColor: ColorPalette.grayChateau
),
selectedState: segmentioState(
backgroundColor: .cyan,
titleFont: font,
titleTextColor: ColorPalette.black
),
highlightedState: segmentioState(
backgroundColor: ColorPalette.whiteSmoke,
titleFont: font,
titleTextColor: ColorPalette.grayChateau
)
)
}
private static func segmentioState(backgroundColor: UIColor, titleFont: UIFont, titleTextColor: UIColor) -> SegmentioState {
return SegmentioState(
backgroundColor: backgroundColor,
titleFont: titleFont,
titleTextColor: titleTextColor
)
}
private static func segmentioIndicatorOptions() -> SegmentioIndicatorOptions {
return SegmentioIndicatorOptions(
type: .bottom,
ratio: 1,
height: 5,
color: ColorPalette.coral
)
}
private static func segmentioHorizontalSeparatorOptions() -> SegmentioHorizontalSeparatorOptions {
return SegmentioHorizontalSeparatorOptions(
type: .topAndBottom,
height: 1,
color: ColorPalette.whiteSmoke
)
}
private static func segmentioVerticalSeparatorOptions() -> SegmentioVerticalSeparatorOptions {
return SegmentioVerticalSeparatorOptions(
ratio: 1,
color: ColorPalette.whiteSmoke
)
}
}

View File

@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.1.5</string>
<string>2.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>25</string>
<string>26</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>

View File

@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
@ -14,21 +18,21 @@
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Y" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zdV-II-bEc">
<rect key="frame" x="270" y="255" width="60" height="90"/>
<rect key="frame" x="157.5" y="288.5" width="60" height="90"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="15m-sK-BMc"/>
<constraint firstAttribute="height" constant="90" id="pHT-4Q-Z9L"/>
</constraints>
<fontDescription key="fontDescription" name="Avenir-Medium" family="Avenir" pointSize="90"/>
<color key="textColor" red="0.95294117647058818" green="0.40000000000000002" blue="0.33333333333333331" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.95294117647058818" green="0.40000000000000002" blue="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.96078431372549022" green="0.96078431372549022" blue="0.96078431372549022" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="0.96078431372549022" green="0.96078431372549022" blue="0.96078431372549022" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="zdV-II-bEc" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="7C2-HE-YjU"/>
<constraint firstItem="zdV-II-bEc" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="Eur-FL-asR"/>
@ -37,7 +41,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
<point key="canvasLocation" x="-36" y="268"/>
</scene>
</scenes>
</document>

View File

@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="Sgi-ow-Mpv">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Sgi-ow-Mpv">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Disaster's guide-->
@ -14,17 +18,17 @@
<viewControllerLayoutGuide type="bottom" id="Cxz-xC-i78"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="6th-V5-ZMU">
<rect key="frame" x="0.0" y="64" width="600" height="536"/>
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="j4J-17-RS0">
<rect key="frame" x="0.0" y="0.0" width="600" height="536"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="603"/>
<connections>
<segue destination="nnH-xc-bez" kind="embed" identifier="EmbedContainerViewController" id="39a-pg-Pje"/>
</connections>
</containerView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="j4J-17-RS0" firstAttribute="top" secondItem="RuD-xI-nzV" secondAttribute="bottom" id="6TL-ta-XXo"/>
<constraint firstAttribute="trailing" secondItem="j4J-17-RS0" secondAttribute="trailing" id="7vA-9i-p0o"/>
@ -54,46 +58,46 @@
<viewControllerLayoutGuide type="bottom" id="d6b-iV-EUm"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="aho-PV-db8" userLabel="Content View">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="cards" translatesAutoresizingMaskIntoConstraints="NO" id="EGM-zw-1hI">
<rect key="frame" x="25" y="24" width="550" height="553"/>
<rect key="frame" x="25" y="24" width="325" height="620"/>
<constraints>
<constraint firstAttribute="height" priority="900" constant="553" id="ffK-Ju-lZo"/>
</constraints>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="pyy-sw-hGC" userLabel="Separator">
<rect key="frame" x="32" y="101" width="536" height="1"/>
<color key="backgroundColor" red="0.96078431372549022" green="0.96078431372549022" blue="0.96078431372549022" alpha="1" colorSpace="calibratedRGB"/>
<rect key="frame" x="32" y="101" width="311" height="1"/>
<color key="backgroundColor" red="0.96078431372549022" green="0.96078431372549022" blue="0.96078431372549022" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="89l-q6-tQe"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Before" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="aoy-p7-Csf">
<rect key="frame" x="32" y="75" width="536" height="19"/>
<rect key="frame" x="32" y="75" width="311" height="19"/>
<constraints>
<constraint firstAttribute="height" constant="19" id="x6o-JU-9JP"/>
</constraints>
<fontDescription key="fontDescription" name="Avenir-Medium" family="Avenir" pointSize="18"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" allowsSelection="NO" showsSelectionImmediatelyOnTouchBegin="NO" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="f8N-44-bJn">
<rect key="frame" x="32" y="160" width="536" height="400"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="separatorColor" red="0.96078431606292725" green="0.96078431606292725" blue="0.96078431606292725" alpha="1" colorSpace="calibratedRGB"/>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" allowsSelection="NO" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="f8N-44-bJn">
<rect key="frame" x="32" y="160" width="311" height="467"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<color key="separatorColor" red="0.96078431606292725" green="0.96078431606292725" blue="0.96078431606292725" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<inset key="separatorInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="Cell" id="C9g-Ij-gNT" customClass="ExampleTableViewCell" customModule="Segmentio_Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="536" height="44"/>
<rect key="frame" x="0.0" y="28" width="311" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="C9g-Ij-gNT" id="3tu-UK-HZb">
<rect key="frame" x="0.0" y="0.0" width="536" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="311" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uyX-0h-rHd">
<rect key="frame" x="25" y="10" width="486" height="24"/>
<rect key="frame" x="25" y="10" width="261" height="24"/>
<fontDescription key="fontDescription" name="Avenir-Light" family="Avenir" pointSize="13"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
@ -118,14 +122,14 @@
</connections>
</tableView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="oval" translatesAutoresizingMaskIntoConstraints="NO" id="t46-Uj-4Ci">
<rect key="frame" x="291" y="122" width="18" height="18"/>
<rect key="frame" x="178.5" y="122" width="18" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="Gki-L9-gmb"/>
<constraint firstAttribute="width" constant="18" id="HcY-Je-7ti"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" red="0.85490196078431369" green="0.85490196078431369" blue="0.85490196078431369" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="0.85490196078431369" green="0.85490196078431369" blue="0.85490196078431369" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="d6b-iV-EUm" firstAttribute="top" secondItem="EGM-zw-1hI" secondAttribute="bottom" constant="23" id="5uZ-0s-poK"/>
<constraint firstItem="f8N-44-bJn" firstAttribute="trailing" secondItem="EGM-zw-1hI" secondAttribute="trailing" constant="-7" id="961-ZU-5yh"/>
@ -165,7 +169,7 @@
<navigationBar key="navigationBar" contentMode="scaleToFill" id="A36-fE-w8g">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<color key="barTintColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="barTintColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="boolean" keyPath="flat" value="YES"/>
</userDefinedRuntimeAttributes>
@ -188,43 +192,43 @@
<viewControllerLayoutGuide type="bottom" id="Lh0-b2-Lg9"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="3on-2h-KRG">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="dwd-YU-7oV" userLabel="Shadow View">
<rect key="frame" x="420" y="0.0" width="180" height="600"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<rect key="frame" x="262" y="0.0" width="113" height="667"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="Ufo-LN-tbg">
<rect key="frame" x="0.0" y="0.0" width="420" height="600"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="0.0" width="262" height="667"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="420" id="1Fe-0J-akh"/>
<constraint firstAttribute="width" constant="262" id="1Fe-0J-akh"/>
</constraints>
<color key="separatorColor" red="0.96078431369999995" green="0.96078431369999995" blue="0.96078431369999995" alpha="1" colorSpace="calibratedRGB"/>
<color key="separatorColor" red="0.96078431369999995" green="0.96078431369999995" blue="0.96078431369999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<inset key="separatorInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
<view key="tableHeaderView" contentMode="scaleToFill" id="Jjd-1j-efW" userLabel="Header">
<rect key="frame" x="0.0" y="0.0" width="420" height="66"/>
<rect key="frame" x="0.0" y="0.0" width="262" height="66"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="IOF-iR-GOe" userLabel="Separator View">
<rect key="frame" x="0.0" y="65" width="420" height="1"/>
<color key="backgroundColor" red="0.95686274509803915" green="0.43529411764705883" blue="0.37647058823529411" alpha="1" colorSpace="calibratedRGB"/>
<rect key="frame" x="0.0" y="65" width="262" height="1"/>
<color key="backgroundColor" red="0.95686274509803915" green="0.43529411764705883" blue="0.37647058823529411" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="ipJ-LO-nfb"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Segmentio" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ON6-SS-qxO">
<rect key="frame" x="16" y="35" width="388" height="22"/>
<rect key="frame" x="16" y="35" width="230" height="22"/>
<constraints>
<constraint firstAttribute="height" constant="22" id="2GY-JW-I97"/>
</constraints>
<fontDescription key="fontDescription" name="Avenir-Medium" family="Avenir" pointSize="17"/>
<color key="textColor" red="0.95686274510000002" green="0.43529411759999997" blue="0.37647058820000001" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.95686274510000002" green="0.43529411759999997" blue="0.37647058820000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="ON6-SS-qxO" firstAttribute="leading" secondItem="Jjd-1j-efW" secondAttribute="leading" constant="16" id="1dw-Yl-bgI"/>
<constraint firstAttribute="trailing" secondItem="IOF-iR-GOe" secondAttribute="trailing" id="AQi-XF-2bn"/>
@ -236,17 +240,17 @@
</view>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" textLabel="bIG-dp-uan" imageView="f8N-oJ-egW" style="IBUITableViewCellStyleDefault" id="k0c-n4-4H9">
<rect key="frame" x="0.0" y="94" width="420" height="44"/>
<rect key="frame" x="0.0" y="94" width="262" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="k0c-n4-4H9" id="9bd-UY-udW">
<rect key="frame" x="0.0" y="0.0" width="420" height="43"/>
<rect key="frame" x="0.0" y="0.0" width="262" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="bIG-dp-uan">
<rect key="frame" x="42" y="0.0" width="363" height="43"/>
<rect key="frame" x="42" y="0.0" width="205" height="43"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="Avenir-Medium" family="Avenir" pointSize="13"/>
<color key="textColor" red="0.20000000000000001" green="0.20000000000000001" blue="0.20000000000000001" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.20000000000000001" green="0.20000000000000001" blue="0.20000000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" image="defaultCheckbox" id="f8N-oJ-egW">
@ -264,7 +268,7 @@
</connections>
</tableView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="dwd-YU-7oV" firstAttribute="leading" secondItem="Ufo-LN-tbg" secondAttribute="trailing" id="STr-vP-7id"/>
<constraint firstItem="Lh0-b2-Lg9" firstAttribute="top" secondItem="Ufo-LN-tbg" secondAttribute="bottom" id="ap0-3r-aiS"/>
@ -275,8 +279,6 @@
<constraint firstAttribute="trailing" secondItem="dwd-YU-7oV" secondAttribute="trailing" id="tIN-F6-Jaf"/>
</constraints>
</view>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<size key="freeformSize" width="600" height="600"/>
<connections>
<outlet property="menuTableView" destination="Ufo-LN-tbg" id="MLh-5f-jgM"/>
<outlet property="menuTableViewWidthConstraint" destination="1Fe-0J-akh" id="m5l-sp-fm3"/>
@ -296,27 +298,27 @@
<viewControllerLayoutGuide type="bottom" id="qlN-Ul-M6a"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="cqi-F1-zxi">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Vkr-KO-SOm" customClass="Segmentio" customModule="Segmentio">
<rect key="frame" x="0.0" y="0.0" width="600" height="125"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="125"/>
<constraints>
<constraint firstAttribute="height" constant="125" id="MbU-cC-j02"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="aMO-Fm-zcR" userLabel="Container">
<rect key="frame" x="0.0" y="125" width="600" height="475"/>
<rect key="frame" x="0.0" y="125" width="375" height="542"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" bounces="NO" pagingEnabled="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" delaysContentTouches="NO" canCancelContentTouches="NO" bouncesZoom="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bPK-CN-TXA">
<rect key="frame" x="0.0" y="0.0" width="600" height="475"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="542"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outlet property="delegate" destination="hoe-Iv-t0i" id="tIm-r4-G4D"/>
</connections>
</scrollView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="bPK-CN-TXA" firstAttribute="top" secondItem="aMO-Fm-zcR" secondAttribute="top" id="83n-Aq-y36"/>
<constraint firstAttribute="trailing" secondItem="bPK-CN-TXA" secondAttribute="trailing" id="AzX-r5-bQP"/>
@ -325,13 +327,13 @@
</constraints>
</view>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="shadow" translatesAutoresizingMaskIntoConstraints="NO" id="i1Z-h8-Bjj">
<rect key="frame" x="0.0" y="125" width="600" height="9"/>
<rect key="frame" x="0.0" y="125" width="375" height="9"/>
<constraints>
<constraint firstAttribute="height" constant="9" id="2DA-Ym-fL4"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="aMO-Fm-zcR" firstAttribute="top" secondItem="Vkr-KO-SOm" secondAttribute="bottom" id="ABa-Nj-ipD"/>
<constraint firstItem="aMO-Fm-zcR" firstAttribute="leading" secondItem="cqi-F1-zxi" secondAttribute="leading" id="VS6-Ut-9kj"/>
@ -375,19 +377,19 @@
<viewControllerLayoutGuide type="bottom" id="riu-eD-uzK"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8VE-5b-uC6">
<rect key="frame" x="0.0" y="0.0" width="600" height="536"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="603"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<extendedEdge key="edgesForExtendedLayout" bottom="YES"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Caz-AG-AcN" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2084" y="285"/>
<point key="canvasLocation" x="2084" y="287"/>
</scene>
</scenes>
<resources>
<image name="cards" width="126" height="54"/>
<image name="cards" width="125" height="53"/>
<image name="defaultCheckbox" width="12" height="12"/>
<image name="menu" width="28" height="14"/>
<image name="oval" width="18" height="18"/>

View File

@ -46,122 +46,65 @@ class ExampleViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
setupSegmentioView()
setupScrollView()
setupBadgeCountForIndex(1)
}
fileprivate func setupSegmentioView() {
segmentioView.setup(
content: segmentioContent(),
style: segmentioStyle,
options: segmentioOptions()
SegmentioBuilder.buildSegmentioView(
segmentioView: segmentioView,
segmentioStyle: segmentioStyle
)
SegmentioBuilder.setupBadgeCountForIndex(segmentioView, index: 1)
segmentioView.selectedSegmentioIndex = selectedSegmentioIndex()
segmentioView.valueDidChange = { [weak self] _, segmentIndex in
if let scrollViewWidth = self?.scrollView.frame.width {
let contentOffsetX = scrollViewWidth * CGFloat(segmentIndex)
self?.scrollView.setContentOffset(CGPoint(x: contentOffsetX, y: 0), animated: true)
self?.scrollView.setContentOffset(
CGPoint(x: contentOffsetX, y: 0),
animated: true
)
}
}
}
fileprivate func setupBadgeCountForIndex(_ index: Int) {
segmentioView.addBadge(at: index, count: 10, color: ColorPalette.coral)
}
fileprivate func segmentioContent() -> [SegmentioItem] {
return [
SegmentioItem(title: "Tornado", image: UIImage(named: "tornado")),
SegmentioItem(title: "Earthquakes", image: UIImage(named: "earthquakes")),
SegmentioItem(title: "Extreme heat", image: UIImage(named: "heat")),
SegmentioItem(title: "Eruption", image: UIImage(named: "eruption")),
SegmentioItem(title: "Floods", image: UIImage(named: "floods")),
SegmentioItem(title: "Wildfires", image: UIImage(named: "wildfires"))
]
}
fileprivate func segmentioOptions() -> SegmentioOptions {
var imageContentMode = UIViewContentMode.center
switch segmentioStyle {
case .imageBeforeLabel, .imageAfterLabel:
imageContentMode = .scaleAspectFit
default:
break
}
return SegmentioOptions(
backgroundColor: ColorPalette.white,
maxVisibleItems: 3,
scrollEnabled: true,
indicatorOptions: segmentioIndicatorOptions(),
horizontalSeparatorOptions: segmentioHorizontalSeparatorOptions(),
verticalSeparatorOptions: segmentioVerticalSeparatorOptions(),
imageContentMode: imageContentMode,
labelTextAlignment: .center,
segmentStates: segmentioStates()
)
}
fileprivate func segmentioStates() -> SegmentioStates {
let font = UIFont.exampleAvenirMedium(ofSize: 13)
return SegmentioStates(
defaultState: segmentioState(
backgroundColor: .clear,
titleFont: font,
titleTextColor: ColorPalette.grayChateau
),
selectedState: segmentioState(
backgroundColor: .clear,
titleFont: font,
titleTextColor: ColorPalette.black
),
highlightedState: segmentioState(
backgroundColor: ColorPalette.whiteSmoke,
titleFont: font,
titleTextColor: ColorPalette.grayChateau
)
)
}
fileprivate func segmentioState(backgroundColor: UIColor, titleFont: UIFont, titleTextColor: UIColor) -> SegmentioState {
return SegmentioState(backgroundColor: backgroundColor, titleFont: titleFont, titleTextColor: titleTextColor)
}
fileprivate func segmentioIndicatorOptions() -> SegmentioIndicatorOptions {
return SegmentioIndicatorOptions(type: .bottom, ratio: 1, height: 5, color: ColorPalette.coral)
}
fileprivate func segmentioHorizontalSeparatorOptions() -> SegmentioHorizontalSeparatorOptions {
return SegmentioHorizontalSeparatorOptions(type: .topAndBottom, height: 1, color: ColorPalette.whiteSmoke)
}
fileprivate func segmentioVerticalSeparatorOptions() -> SegmentioVerticalSeparatorOptions {
return SegmentioVerticalSeparatorOptions(ratio: 1, color: ColorPalette.whiteSmoke)
}
// Example viewControllers
fileprivate func preparedViewControllers() -> [ContentViewController] {
let tornadoController = ContentViewController.create()
tornadoController.disaster = Disaster(cardName: "Before tornado", hints: Hints.tornado)
tornadoController.disaster = Disaster(
cardName: "Before tornado",
hints: Hints.tornado
)
let earthquakesController = ContentViewController.create()
earthquakesController.disaster = Disaster(cardName: "Before earthquakes", hints: Hints.earthquakes)
earthquakesController.disaster = Disaster(
cardName: "Before earthquakes",
hints: Hints.earthquakes
)
let extremeHeatController = ContentViewController.create()
extremeHeatController.disaster = Disaster(cardName: "Before extreme heat", hints: Hints.extremeHeat)
extremeHeatController.disaster = Disaster(
cardName: "Before extreme heat",
hints: Hints.extremeHeat
)
let eruptionController = ContentViewController.create()
eruptionController.disaster = Disaster(cardName: "Before eruption", hints: Hints.eruption)
eruptionController.disaster = Disaster(
cardName: "Before eruption",
hints: Hints.eruption
)
let floodsController = ContentViewController.create()
floodsController.disaster = Disaster(cardName: "Before floods", hints: Hints.floods)
floodsController.disaster = Disaster(
cardName: "Before floods",
hints: Hints.floods
)
let wildfiresController = ContentViewController.create()
wildfiresController.disaster = Disaster(cardName: "Before wildfires", hints: Hints.wildfires)
wildfiresController.disaster = Disaster(
cardName: "Before wildfires",
hints: Hints.wildfires
)
return [
tornadoController,

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright © 2015 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
@ -18,4 +18,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

@ -1,5 +1,5 @@
##Segmentio
[![Platform](http://img.shields.io/badge/platform-iOS-blue.svg?style=flat)](https://cocoapods.org/?q=segmentio) [![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/Yalantis/Segmentio/blob/master/LICENSE) ![Swift 2.2.x](https://img.shields.io/badge/Swift-2.2.x-orange.svg) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Platform](http://img.shields.io/badge/platform-iOS-blue.svg?style=flat)](https://cocoapods.org/?q=segmentio) [![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/Yalantis/Segmentio/blob/master/LICENSE) ![Swift 3.x](https://img.shields.io/badge/Swift-3.0-orange.svg) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
Animated top/bottom segmented control written in Swift.
@ -19,14 +19,14 @@ Check this <a href="https://dribbble.com/shots/2820372-Segmentio-Component">proj
```ruby
use_frameworks!
pod 'Segmentio', '~> 2.0'
pod 'Segmentio', '~> 2.1'
```
*CocoaPods v1.1.0 or later required*
####[Carthage](http://github.com/Carthage/Carthage)
```ruby
github "Yalantis/Segmentio" ~> 2.0
github "Yalantis/Segmentio" ~> 2.1
```
##Usage
@ -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,15 +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,
labelTextAlignment: NSTextAlignment.Center,
segmentStates: SegmentioStates // tuple of SegmentioState (defaultState, selectState, highlightedState)
backgroundColor: .white,
maxVisibleItems: 3,
scrollEnabled: true,
indicatorOptions: SegmentioIndicatorOptions,
horizontalSeparatorOptions: SegmentioHorizontalSeparatorOptions,
verticalSeparatorOptions: SegmentioVerticalSeparatorOptions,
imageContentMode: .center,
labelTextAlignment: .center,
segmentStates: SegmentioStates
)
```
@ -123,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
)
```
@ -134,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
)
```
@ -144,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
)
```
@ -153,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
)
)
```
@ -180,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
@ -198,4 +198,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

@ -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

@ -272,7 +272,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@ -312,7 +312,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";

View File

@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.1.5</string>
<string>2.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>

View File

@ -173,35 +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.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.0
)
addConstraints([segmentTitleLabelHorizontalCenterConstraint, segmentTitleLabelVerticalCenterConstraint])
addConstraints([
segmentTitleLabelTrailingConstraint,
segmentTitleLabelVerticalCenterConstraint,
segmentTitleLabelLeadingConstraint
])
}
fileprivate func setupImageContainerConstraints() {
@ -220,7 +228,7 @@ class SegmentioCell: UICollectionViewCell {
toItem: imageContainerView,
attribute: .top,
multiplier: 1,
constant: 0.0
constant: 0
)
let segmentImageViewLeadingConstraint =
@ -231,7 +239,7 @@ class SegmentioCell: UICollectionViewCell {
toItem: imageContainerView,
attribute: .leading,
multiplier: 1,
constant: 0.0
constant: 0
)
let segmentImageViewTrailingConstraint =
@ -242,7 +250,7 @@ class SegmentioCell: UICollectionViewCell {
toItem: imageContainerView,
attribute: .trailing,
multiplier: 1,
constant: 0.0
constant: 0
)
let segmentImageViewBottomConstraint =
@ -253,9 +261,14 @@ class SegmentioCell: UICollectionViewCell {
toItem: imageContainerView,
attribute: .bottom,
multiplier: 1,
constant: 0.0
constant: 0
)
addConstraints([segmentImageViewBottomConstraint, segmentImageViewTrailingConstraint, segmentImageViewLeadingConstraint, segmentImageViewTopConstraint])
addConstraints([
segmentImageViewBottomConstraint,
segmentImageViewTrailingConstraint,
segmentImageViewLeadingConstraint,
segmentImageViewTopConstraint
])
}
@ -267,6 +280,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

@ -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

@ -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 {
@ -45,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
@ -57,20 +55,8 @@ open class Segmentio: UIView {
fileprivate var indicatorLayer: CAShapeLayer?
fileprivate var selectedLayer: CAShapeLayer?
fileprivate var cachedOrientation: UIInterfaceOrientation? = UIApplication.shared.statusBarOrientation {
didSet {
if cachedOrientation != oldValue {
reloadSegmentio()
}
}
}
// MARK: - Lifecycle
deinit {
NotificationCenter.default.removeObserver(self)
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
@ -81,14 +67,13 @@ open class Segmentio: UIView {
commonInit()
}
open override func layoutSubviews() {
super.layoutSubviews()
reloadSegmentio()
}
fileprivate func commonInit() {
setupSegmentedCollectionView()
NotificationCenter.default.addObserver(
self,
selector: #selector(Segmentio.handleOrientationNotification),
name: NSNotification.Name.UIDeviceOrientationDidChange,
object: nil
)
}
fileprivate func setupSegmentedCollectionView() {
@ -146,12 +131,6 @@ open class Segmentio: UIView {
)
}
// MARK: - Handle orientation notification
@objc fileprivate func handleOrientationNotification() {
cachedOrientation = UIApplication.shared.statusBarOrientation
}
// MARK: - Setups:
// MARK: Main setup
@ -342,7 +321,8 @@ open class Segmentio: UIView {
// MARK: - Actions:
// MARK: Reload segmentio
fileprivate func reloadSegmentio() {
public func reloadSegmentio() {
segmentioCollectionView?.collectionViewLayout.invalidateLayout()
segmentioCollectionView?.reloadData()
scrollToItemAtContext()
moveShapeLayerAtContext()
@ -408,9 +388,10 @@ open class Segmentio: UIView {
)
}
if context.isFirstOrSecondVisibleCell == true {
if context.isFirstOrSecondVisibleCell == true && selectedSegmentioIndex != -1 {
let newIndex = selectedSegmentioIndex - (context.isFirstIndex ? 1 : 0)
let newIndexPath = IndexPath(item: newIndex, section: numberOfSections - 1)
segmentioCollectionView?.scrollToItem(
at: newIndexPath,
at: UICollectionViewScrollPosition(),
@ -438,7 +419,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

@ -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
@ -84,7 +84,7 @@ public struct SegmentioVerticalSeparatorOptions {
var ratio: CGFloat
var color: UIColor
public init(ratio: CGFloat = 1.0, color: UIColor = .darkGray) {
public init(ratio: CGFloat = 1, color: UIColor = .darkGray) {
self.ratio = ratio
self.color = color
}
@ -107,7 +107,7 @@ public struct SegmentioIndicatorOptions {
var height: CGFloat
var color: UIColor
public init(type: SegmentioIndicatorType = .bottom, ratio: CGFloat = 1.0, height: CGFloat = 2.0, color: UIColor = .orange) {
public init(type: SegmentioIndicatorType = .bottom, ratio: CGFloat = 1, height: CGFloat = 2, color: UIColor = .orange) {
self.type = type
self.ratio = ratio
self.height = height
@ -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
}
}