Merge pull request #11 from Yalantis/swift3

Swift3
This commit is contained in:
Serhii Butenko 2016-10-10 08:23:15 +03:00 committed by GitHub
commit 34cf755361
36 changed files with 734 additions and 683 deletions

1
.swift-version Normal file
View File

@ -0,0 +1 @@
3.0

View File

@ -13,4 +13,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: 761653fe0a6001fe4076ba25b04e279672ecc970
COCOAPODS: 1.0.1
COCOAPODS: 1.1.0.rc.2

View File

@ -13,4 +13,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: 761653fe0a6001fe4076ba25b04e279672ecc970
COCOAPODS: 1.0.1
COCOAPODS: 1.1.0.rc.2

View File

@ -496,7 +496,7 @@
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
47BEF9D903506B003EA5C2B249729489 /* Debug */ = {
015A368F878AC3E2CEAE21DDE8026304 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
@ -514,6 +514,7 @@
CLANG_WARN_OBJC_ROOT_CLASS = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGNING_REQUIRED = NO;
COPY_PHASE_STRIP = NO;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
@ -533,17 +534,59 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
ONLY_ACTIVE_ARCH = YES;
PROVISIONING_PROFILE_SPECIFIER = NO_SIGNING/;
STRIP_INSTALLED_PRODUCT = NO;
SYMROOT = "${SRCROOT}/../build";
};
name = Debug;
};
6A88DE4855BF46A99DED1138AC50611B /* Debug */ = {
44CDBB6D11DE06DB64D6268622BDC47E /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 37602088D7DDBEBF54BCE7CAF18CB105 /* Pods-Segmentio_Example.debug.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGNING_REQUIRED = NO;
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_PREPROCESSOR_DEFINITIONS = (
"POD_CONFIGURATION_RELEASE=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PROVISIONING_PROFILE_SPECIFIER = NO_SIGNING/;
STRIP_INSTALLED_PRODUCT = NO;
SYMROOT = "${SRCROOT}/../build";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
6939D89BCF3CB71D8A0CB554AEAC1779 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = AAF3441A43AA58E58A7340FA1E66271B /* Segmentio.xcconfig */;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "";
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
@ -552,33 +595,31 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
INFOPLIST_FILE = "Target Support Files/Pods-Segmentio_Example/Info.plist";
GCC_PREFIX_HEADER = "Target Support Files/Segmentio/Segmentio-prefix.pch";
INFOPLIST_FILE = "Target Support Files/Segmentio/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACH_O_TYPE = staticlib;
MODULEMAP_FILE = "Target Support Files/Pods-Segmentio_Example/Pods-Segmentio_Example.modulemap";
MODULEMAP_FILE = "Target Support Files/Segmentio/Segmentio.modulemap";
MTL_ENABLE_DEBUG_INFO = YES;
OTHER_LDFLAGS = "";
OTHER_LIBTOOLFLAGS = "";
PODS_ROOT = "$(SRCROOT)";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = Pods_Segmentio_Example;
PRODUCT_NAME = Segmentio;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
name = Debug;
};
847944553F66C9C9C8CF5EA5A12838E5 /* Release */ = {
69F41B3AE04E5DCE90065CD8E029712C /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 808E8A2F66FEF9BFA423C8B51FEB3FD3 /* Pods-Segmentio_Example.release.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "";
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
@ -624,44 +665,6 @@
};
name = Debug;
};
AAF678CED40D3499169D10F63CA0719E /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_PREPROCESSOR_DEFINITIONS = (
"POD_CONFIGURATION_RELEASE=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
STRIP_INSTALLED_PRODUCT = NO;
SYMROOT = "${SRCROOT}/../build";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
B39C8A659F54F5D7007A70CE400454EA /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = AAF3441A43AA58E58A7340FA1E66271B /* Segmentio.xcconfig */;
@ -679,11 +682,13 @@
};
name = Release;
};
B54261FEDDC960542CA187AA5E14BC7D /* Debug */ = {
BF58FEE71132386297AFD4D409190547 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = AAF3441A43AA58E58A7340FA1E66271B /* Segmentio.xcconfig */;
baseConfigurationReference = 37602088D7DDBEBF54BCE7CAF18CB105 /* Pods-Segmentio_Example.debug.xcconfig */;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "";
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
@ -692,14 +697,18 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_PREFIX_HEADER = "Target Support Files/Segmentio/Segmentio-prefix.pch";
INFOPLIST_FILE = "Target Support Files/Segmentio/Info.plist";
INFOPLIST_FILE = "Target Support Files/Pods-Segmentio_Example/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MODULEMAP_FILE = "Target Support Files/Segmentio/Segmentio.modulemap";
MACH_O_TYPE = staticlib;
MODULEMAP_FILE = "Target Support Files/Pods-Segmentio_Example/Pods-Segmentio_Example.modulemap";
MTL_ENABLE_DEBUG_INFO = YES;
PRODUCT_NAME = Segmentio;
OTHER_LDFLAGS = "";
OTHER_LIBTOOLFLAGS = "";
PODS_ROOT = "$(SRCROOT)";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = Pods_Segmentio_Example;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@ -709,11 +718,13 @@
};
name = Debug;
};
F03A1D5CC9DD916A3B05610779B9C8F0 /* Release */ = {
E8435E0DCC8F7A80386C452616DACB34 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = AAF3441A43AA58E58A7340FA1E66271B /* Segmentio.xcconfig */;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "";
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
@ -732,6 +743,7 @@
PRODUCT_NAME = Segmentio;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
@ -744,8 +756,8 @@
2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */ = {
isa = XCConfigurationList;
buildConfigurations = (
47BEF9D903506B003EA5C2B249729489 /* Debug */,
AAF678CED40D3499169D10F63CA0719E /* Release */,
015A368F878AC3E2CEAE21DDE8026304 /* Debug */,
44CDBB6D11DE06DB64D6268622BDC47E /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
@ -753,8 +765,8 @@
785D3215E776BE829EB1D98F89F1A8C1 /* Build configuration list for PBXNativeTarget "Segmentio" */ = {
isa = XCConfigurationList;
buildConfigurations = (
B54261FEDDC960542CA187AA5E14BC7D /* Debug */,
F03A1D5CC9DD916A3B05610779B9C8F0 /* Release */,
6939D89BCF3CB71D8A0CB554AEAC1779 /* Debug */,
E8435E0DCC8F7A80386C452616DACB34 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
@ -771,8 +783,8 @@
CC37EAE0F58FC2B11F123B84FE6B0FAC /* Build configuration list for PBXNativeTarget "Pods-Segmentio_Example" */ = {
isa = XCConfigurationList;
buildConfigurations = (
6A88DE4855BF46A99DED1138AC50611B /* Debug */,
847944553F66C9C9C8CF5EA5A12838E5 /* Release */,
BF58FEE71132386297AFD4D409190547 /* Debug */,
69F41B3AE04E5DCE90065CD8E029712C /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;

View File

@ -35,6 +35,8 @@ 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.</string>
<key>License</key>
<string>MIT</string>
<key>Title</key>
<string>Segmentio</string>
<key>Type</key>

View File

@ -1,3 +1,4 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES
FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/Segmentio"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1

View File

@ -1,3 +1,4 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES
FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/Segmentio"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1

View File

@ -244,6 +244,7 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0800;
};
};
};
@ -321,7 +322,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
@ -388,7 +389,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@ -426,7 +427,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
@ -450,6 +451,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@ -472,6 +474,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;

View File

@ -13,10 +13,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UIDevice.currentDevice().beginGeneratingDeviceOrientationNotifications()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIDevice.current.beginGeneratingDeviceOrientationNotifications()
AppearanceConfigurator.configureNavigationBar()
return true
}
}
}

View File

@ -12,16 +12,15 @@ extension String {
func stringFromCamelCase() -> String {
var string = self
string = string.stringByReplacingOccurrencesOfString(
"([a-z])([A-Z])",
withString: "$1 $2",
options: .RegularExpressionSearch,
range: Range<String.Index>(string.startIndex..<string.endIndex)
string = string.replacingOccurrences(
of: "([a-z])([A-Z])",
with: "$1 $2",
options: .regularExpression,
range: nil
)
string.replaceSubrange(startIndex...startIndex, with: String(self[startIndex]))
string.replaceRange(startIndex...startIndex, with: String(self[startIndex]))
return String(string.characters.prefix(1)).capitalizedString + String(string.lowercaseString.characters.dropFirst())
return String(string.characters.prefix(1)).capitalized + String(string.lowercased().characters.dropFirst())
}
}
}

View File

@ -10,12 +10,12 @@ import UIKit
extension UIFont {
class func exampleAvenirMediumWithSize(size: CGFloat) -> UIFont {
return UIFont(name: "Avenir-Book", size: size) ?? UIFont.systemFontOfSize(size)
class func exampleAvenirMedium(ofSize size: CGFloat) -> UIFont {
return UIFont(name: "Avenir-Book", size: size) ?? UIFont.systemFont(ofSize: size)
}
class func exampleAvenirLightWithSize(size: CGFloat) -> UIFont {
return UIFont(name: "Avenir-Light", size: size) ?? UIFont.systemFontOfSize(size)
class func exampleAvenirLight(ofSize size: CGFloat) -> UIFont {
return UIFont(name: "Avenir-Light", size: size) ?? UIFont.systemFont(ofSize: size)
}
}
}

View File

@ -28,15 +28,15 @@ private var flatAssociatedObjectKey: UInt8 = 0
set {
if (newValue) {
let void = UIImage()
setBackgroundImage(void, forBarPosition: .Any, barMetrics: .Default)
setBackgroundImage(void, for: .any, barMetrics: .default)
shadowImage = void
} else {
setBackgroundImage(nil, forBarPosition: .Any, barMetrics: .Default)
setBackgroundImage(nil, for: .any, barMetrics: .default)
shadowImage = nil
}
objc_setAssociatedObject(self, &flatAssociatedObjectKey, NSNumber(bool: newValue),
objc_setAssociatedObject(self, &flatAssociatedObjectKey, NSNumber(value: newValue as Bool),
objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
}

View File

@ -11,16 +11,16 @@ import UIKit
class AppearanceConfigurator {
class func configureNavigationBar() {
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
UIApplication.shared.statusBarStyle = .lightContent
UINavigationBar.appearance().barTintColor = ColorPalette.WhiteColor
UINavigationBar.appearance().translucent = false
UINavigationBar.appearance().tintColor = ColorPalette.BlackColor
UINavigationBar.appearance().barTintColor = ColorPalette.white
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().tintColor = ColorPalette.black
let attributes = [
NSFontAttributeName : UIFont.exampleAvenirMediumWithSize(17),
NSForegroundColorAttributeName : ColorPalette.BlackColor
NSFontAttributeName : UIFont.exampleAvenirMedium(ofSize: 17),
NSForegroundColorAttributeName : ColorPalette.black
]
UINavigationBar.appearance().titleTextAttributes = attributes
}
}
}

View File

@ -9,9 +9,11 @@
import UIKit
struct ColorPalette {
static let WhiteColor = UIColor(red: 255, green: 255, blue: 255)
static let BlackColor = UIColor(red: 3, green: 3, blue: 3)
static let CoralColor = UIColor(red: 244, green: 111, blue: 96)
static let WhiteSmokeColor = UIColor(red: 245, green: 245, blue: 245)
static let GrayChateauColor = UIColor(red: 163, green: 164, blue: 168)
}
static let white = UIColor(red: 255, green: 255, blue: 255)
static let black = UIColor(red: 3, green: 3, blue: 3)
static let coral = UIColor(red: 244, green: 111, blue: 96)
static let whiteSmoke = UIColor(red: 245, green: 245, blue: 245)
static let grayChateau = UIColor(red: 163, green: 164, blue: 168)
}

View File

@ -7,35 +7,35 @@
//
struct Hints {
static let Tornado = [
static let tornado = [
"1. Move immediately to the special underground shelter whenever possible.",
"2. If unable to go underground, stay in a windowless, interior room on the lowest possible floor.",
"3. Remain in your shelter until the danger of tornadoes has passed.",
"4. Exit your shelter carefully, and exercise caution moving around in a tornado stricken area."
]
static let Earthquakes = [
static let earthquakes = [
"1. Make sure you have a fire extinguisher, first aid kit, a battery-powered radio, a flashlight, and extra batteries at home.",
"2. Learn how to turn off the gas, water, and electricity.",
"3. Make up a plan of where to meet your family after an earthquake. Don't leave heavy objects on shelves.",
"4. Dont panic."
]
static let ExtremeHeat = [
static let extremeHeat = [
"1. Know the Terms: Heat Wave, Heat Index, Heat Cramps, Heat Exhaustion, Heat Stroke, Sun Stroke.",
"2. Install window air conditioners snugly; insulate if necessary.",
"3. Check air-conditioning ducts for proper insulation.",
"4. Install temporary window reflectors (for use between windows and drapes), such as aluminum foil-covered cardboard, to reflect heat back outside."
]
static let Eruption = [
static let eruption = [
"1. Know your community's warning system.",
"2. Get familiar with the evacuation procedures.",
"3. Develop a household evacuation plan. Figure out what you'll need to do if you hear the sirens go off.",
"4. Stock up on necessities. Store at least a three-day supply of food and portable water at your home."
]
static let Floods = [
static let floods = [
"1. Be aware of your area's flood risk before the expected rain is going to hit.",
"2. Check to see if you have insurance that covers flooding.",
"3. Keep insurance policies, documents, and other valuables in a safe-deposit box, that is located up high and out of harm's way.",
@ -43,11 +43,11 @@ struct Hints {
"5. Identify where you could go if told to evacuate."
]
static let Wildfires = [
static let wildfires = [
"1. Make a disaster supply kit and have a family plan.",
"2. Design and landscape your home with wildfire safety in mind: select materials and plants that can help contain fire rather than fuel it.",
"3. Teach each family member how to use a fire extinguisher (ABC type) and show them where it's kept.",
"4. Dont panic."
]
}
}

View File

@ -9,29 +9,29 @@
import UIKit
private func yal_isPhone6() -> Bool {
let size = UIScreen.mainScreen().bounds.size
let size = UIScreen.main.bounds.size
let minSide = min(size.height, size.width)
let maxSide = max(size.height, size.width)
return (fabs(minSide - 375.0) < 0.01) && (fabs(maxSide - 667.0) < 0.01)
}
class ExampleTableViewCell: UITableViewCell {
@IBOutlet private weak var hintLabel: UILabel!
@IBOutlet fileprivate weak var hintLabel: UILabel!
}
class ContentViewController: UIViewController {
@IBOutlet private weak var cardNameLabel: UILabel!
@IBOutlet private weak var hintTableView: UITableView!
@IBOutlet private weak var bottomCardConstraint: NSLayoutConstraint!
@IBOutlet private weak var heightConstraint: NSLayoutConstraint!
@IBOutlet fileprivate weak var cardNameLabel: UILabel!
@IBOutlet fileprivate weak var hintTableView: UITableView!
@IBOutlet fileprivate weak var bottomCardConstraint: NSLayoutConstraint!
@IBOutlet fileprivate weak var heightConstraint: NSLayoutConstraint!
var disaster: Disaster?
private var hints: [String]?
fileprivate var hints: [String]?
class func create() -> ContentViewController {
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
return mainStoryboard.instantiateViewControllerWithIdentifier(String(self)) as! ContentViewController
return mainStoryboard.instantiateViewController(withIdentifier: String(describing: self)) as! ContentViewController
}
// MARK: - Lifecycle
@ -60,14 +60,14 @@ class ContentViewController: UIViewController {
extension ContentViewController: UITableViewDataSource {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return hints?.count ?? 0
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! ExampleTableViewCell
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! ExampleTableViewCell
cell.hintLabel?.text = hints?[indexPath.row]
return cell
}
}
}

View File

@ -9,13 +9,13 @@
import UIKit
import Segmentio
private let animateDuration: NSTimeInterval = 0.6
private let animateDuration: TimeInterval = 0.6
class EmbedContainerViewController: UIViewController {
var style = SegmentioStyle.OnlyImage
var style = SegmentioStyle.onlyImage
private var currentViewController: UIViewController?
fileprivate var currentViewController: UIViewController?
// MARK: - Lifecycle
@ -26,7 +26,7 @@ class EmbedContainerViewController: UIViewController {
// MARK: - Private functions
private func presentController(controller: UIViewController) {
fileprivate func presentController(_ controller: UIViewController) {
if let _ = currentViewController {
removeCurrentViewController()
}
@ -34,29 +34,29 @@ class EmbedContainerViewController: UIViewController {
addChildViewController(controller)
view.addSubview(controller.view)
currentViewController = controller
controller.didMoveToParentViewController(self)
controller.didMove(toParentViewController: self)
}
private func controller(style: SegmentioStyle) -> ExampleViewController {
fileprivate func controller(_ style: SegmentioStyle) -> ExampleViewController {
let controller = ExampleViewController.create()
controller.segmentioStyle = style
controller.view.frame = view.bounds
return controller
}
private func removeCurrentViewController() {
currentViewController?.willMoveToParentViewController(nil)
fileprivate func removeCurrentViewController() {
currentViewController?.willMove(toParentViewController: nil)
currentViewController?.view.removeFromSuperview()
currentViewController?.removeFromParentViewController()
}
private func swapCurrentController(controller: UIViewController) {
currentViewController?.willMoveToParentViewController(nil)
fileprivate func swapCurrentController(_ controller: UIViewController) {
currentViewController?.willMove(toParentViewController: nil)
addChildViewController(controller)
view.addSubview(controller.view)
UIView.animateWithDuration(
animateDuration,
UIView.animate(
withDuration: animateDuration,
animations: {
controller.view.alpha = 1
self.currentViewController?.view.alpha = 0
@ -65,15 +65,15 @@ class EmbedContainerViewController: UIViewController {
self.currentViewController?.view.removeFromSuperview()
self.currentViewController?.removeFromParentViewController()
self.currentViewController = controller
self.currentViewController?.didMoveToParentViewController(self)
self.currentViewController?.didMove(toParentViewController: self)
}
)
}
// MARK: - Public functions
func swapViewControllers(style: SegmentioStyle) {
func swapViewControllers(_ style: SegmentioStyle) {
swapCurrentController(controller(style))
}
}
}

View File

@ -11,14 +11,14 @@ import Segmentio
class ExampleViewController: UIViewController {
var segmentioStyle = SegmentioStyle.ImageOverLabel
var segmentioStyle = SegmentioStyle.imageOverLabel
@IBOutlet private weak var segmentViewHeightConstraint: NSLayoutConstraint!
@IBOutlet private weak var segmentioView: Segmentio!
@IBOutlet private weak var containerView: UIView!
@IBOutlet private weak var scrollView: UIScrollView!
@IBOutlet fileprivate weak var segmentViewHeightConstraint: NSLayoutConstraint!
@IBOutlet fileprivate weak var segmentioView: Segmentio!
@IBOutlet fileprivate weak var containerView: UIView!
@IBOutlet fileprivate weak var scrollView: UIScrollView!
private lazy var viewControllers: [UIViewController] = {
fileprivate lazy var viewControllers: [UIViewController] = {
return self.preparedViewControllers()
}()
@ -26,7 +26,7 @@ class ExampleViewController: UIViewController {
class func create() -> ExampleViewController {
let board = UIStoryboard(name: "Main", bundle: nil)
return board.instantiateViewControllerWithIdentifier(String(self)) as! ExampleViewController
return board.instantiateViewController(withIdentifier: String(describing: self)) as! ExampleViewController
}
// MARK: - Lifecycle
@ -35,23 +35,23 @@ class ExampleViewController: UIViewController {
super.viewDidLoad()
switch segmentioStyle {
case .OnlyLabel, .ImageBeforeLabel, .ImageAfterLabel:
case .onlyLabel, .imageBeforeLabel, .imageAfterLabel:
segmentViewHeightConstraint.constant = 50
case .OnlyImage:
case .onlyImage:
segmentViewHeightConstraint.constant = 100
default:
break
}
}
override func viewDidAppear(animated: Bool) {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
setupSegmentioView()
setupScrollView()
setupBadgeCountForIndex(1)
}
private func setupSegmentioView() {
fileprivate func setupSegmentioView() {
segmentioView.setup(
content: segmentioContent(),
style: segmentioStyle,
@ -63,23 +63,16 @@ class ExampleViewController: UIViewController {
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)
}
}
}
private func setupBadgeCountForIndex(index: Int) {
segmentioView.setupBadgeAtIndex(
index,
count: 10,
color: ColorPalette.CoralColor
)
fileprivate func setupBadgeCountForIndex(_ index: Int) {
segmentioView.addBadge(at: index, count: 10, color: ColorPalette.coral)
}
private func segmentioContent() -> [SegmentioItem] {
fileprivate func segmentioContent() -> [SegmentioItem] {
return [
SegmentioItem(title: "Tornado", image: UIImage(named: "tornado")),
SegmentioItem(title: "Earthquakes", image: UIImage(named: "earthquakes")),
@ -90,97 +83,85 @@ class ExampleViewController: UIViewController {
]
}
private func segmentioOptions() -> SegmentioOptions {
var imageContentMode = UIViewContentMode.Center
fileprivate func segmentioOptions() -> SegmentioOptions {
var imageContentMode = UIViewContentMode.center
switch segmentioStyle {
case .ImageBeforeLabel, .ImageAfterLabel:
imageContentMode = .ScaleAspectFit
case .imageBeforeLabel, .imageAfterLabel:
imageContentMode = .scaleAspectFit
default:
break
}
return SegmentioOptions(
backgroundColor: ColorPalette.WhiteColor,
backgroundColor: ColorPalette.white,
maxVisibleItems: 3,
scrollEnabled: true,
indicatorOptions: segmentioIndicatorOptions(),
horizontalSeparatorOptions: segmentioHorizontalSeparatorOptions(),
verticalSeparatorOptions: segmentioVerticalSeparatorOptions(),
imageContentMode: imageContentMode,
labelTextAlignment: .Center,
labelTextAlignment: .center,
segmentStates: segmentioStates()
)
}
private func segmentioStates() -> SegmentioStates {
let font = UIFont.exampleAvenirMediumWithSize(13)
fileprivate func segmentioStates() -> SegmentioStates {
let font = UIFont.exampleAvenirMedium(ofSize: 13)
return SegmentioStates(
defaultState: segmentioState(
backgroundColor: UIColor.clearColor(),
backgroundColor: .clear,
titleFont: font,
titleTextColor: ColorPalette.GrayChateauColor
titleTextColor: ColorPalette.grayChateau
),
selectedState: segmentioState(
backgroundColor: UIColor.clearColor(),
backgroundColor: .clear,
titleFont: font,
titleTextColor: ColorPalette.BlackColor
titleTextColor: ColorPalette.black
),
highlightedState: segmentioState(
backgroundColor: ColorPalette.WhiteSmokeColor,
backgroundColor: ColorPalette.whiteSmoke,
titleFont: font,
titleTextColor: ColorPalette.GrayChateauColor
titleTextColor: ColorPalette.grayChateau
)
)
}
private func segmentioState(backgroundColor backgroundColor: UIColor, titleFont: UIFont, titleTextColor: UIColor) -> SegmentioState {
fileprivate func segmentioState(backgroundColor: UIColor, titleFont: UIFont, titleTextColor: UIColor) -> SegmentioState {
return SegmentioState(backgroundColor: backgroundColor, titleFont: titleFont, titleTextColor: titleTextColor)
}
private func segmentioIndicatorOptions() -> SegmentioIndicatorOptions {
return SegmentioIndicatorOptions(
type: .Bottom,
ratio: 1,
height: 5,
color: ColorPalette.CoralColor
)
fileprivate func segmentioIndicatorOptions() -> SegmentioIndicatorOptions {
return SegmentioIndicatorOptions(type: .bottom, ratio: 1, height: 5, color: ColorPalette.coral)
}
private func segmentioHorizontalSeparatorOptions() -> SegmentioHorizontalSeparatorOptions {
return SegmentioHorizontalSeparatorOptions(
type: .TopAndBottom,
height: 1,
color: ColorPalette.WhiteSmokeColor
)
fileprivate func segmentioHorizontalSeparatorOptions() -> SegmentioHorizontalSeparatorOptions {
return SegmentioHorizontalSeparatorOptions(type: .topAndBottom, height: 1, color: ColorPalette.whiteSmoke)
}
private func segmentioVerticalSeparatorOptions() -> SegmentioVerticalSeparatorOptions {
return SegmentioVerticalSeparatorOptions(
ratio: 1,
color: ColorPalette.WhiteSmokeColor
)
fileprivate func segmentioVerticalSeparatorOptions() -> SegmentioVerticalSeparatorOptions {
return SegmentioVerticalSeparatorOptions(ratio: 1, color: ColorPalette.whiteSmoke)
}
// Example viewControllers
private func preparedViewControllers() -> [ContentViewController] {
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,
@ -192,49 +173,48 @@ class ExampleViewController: UIViewController {
]
}
private func selectedSegmentioIndex() -> Int {
fileprivate func selectedSegmentioIndex() -> Int {
return 0
}
// MARK: - Setup container view
private func setupScrollView() {
fileprivate func setupScrollView() {
scrollView.contentSize = CGSize(
width: UIScreen.mainScreen().bounds.width * CGFloat(viewControllers.count),
width: UIScreen.main.bounds.width * CGFloat(viewControllers.count),
height: containerView.frame.height
)
for (index, viewController) in viewControllers.enumerate() {
for (index, viewController) in viewControllers.enumerated() {
viewController.view.frame = CGRect(
x: UIScreen.mainScreen().bounds.width * CGFloat(index),
x: UIScreen.main.bounds.width * CGFloat(index),
y: 0,
width: scrollView.frame.width,
height: scrollView.frame.height
)
addChildViewController(viewController)
scrollView.addSubview(viewController.view, options: .UseAutoresize) // module's extension
viewController.didMoveToParentViewController(self)
scrollView.addSubview(viewController.view, options: .useAutoresize) // module's extension
viewController.didMove(toParentViewController: self)
}
}
// MARK: - Actions
private func goToControllerAtIndex(index: Int) {
fileprivate func goToControllerAtIndex(_ index: Int) {
segmentioView.selectedSegmentioIndex = index
}
}
extension ExampleViewController: UIScrollViewDelegate {
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
let currentPage = floor(scrollView.contentOffset.x / scrollView.frame.width)
segmentioView.selectedSegmentioIndex = Int(currentPage)
}
func scrollViewDidScroll(scrollView: UIScrollView) {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
scrollView.contentSize = CGSize(width: scrollView.contentSize.width, height: 0)
}
}
}

View File

@ -11,8 +11,8 @@ import Segmentio
class HomeViewController: UIViewController {
private var currentStyle = SegmentioStyle.OnlyImage
private var containerViewController: EmbedContainerViewController?
fileprivate var currentStyle = SegmentioStyle.onlyImage
fileprivate var containerViewController: EmbedContainerViewController?
// MARK: - Lifecycle
@ -20,26 +20,26 @@ class HomeViewController: UIViewController {
super.viewDidLoad()
}
override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
return true
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == String(EmbedContainerViewController.self) {
containerViewController = segue.destinationViewController as? EmbedContainerViewController
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == String(describing: EmbedContainerViewController.self) {
containerViewController = segue.destination as? EmbedContainerViewController
containerViewController?.style = currentStyle
}
}
// MARK: - Actions
@IBAction private func showMenu(sender: UIBarButtonItem) {
@IBAction fileprivate func showMenu(_ sender: UIBarButtonItem) {
SideMenuViewController.create().showSideMenu(
viewController: self,
currentStyle: currentStyle,
sideMenuDidHide: { [weak self] style in
self?.dismissViewControllerAnimated(
false,
self?.dismiss(
animated: false,
completion: {
if self?.currentStyle != style {
self?.currentStyle = style
@ -51,4 +51,4 @@ class HomeViewController: UIViewController {
)
}
}
}

View File

@ -9,9 +9,9 @@
import UIKit
import Segmentio
typealias SideMenuHandler = ((style: SegmentioStyle) -> Void)
typealias SideMenuHandler = ((_ style: SegmentioStyle) -> Void)
private let animationDuration: NSTimeInterval = 0.3
private let animationDuration: TimeInterval = 0.3
private let selectedCheckboxImage = UIImage(named: "selectedCheckbox")
private let defaultCheckboxImage = UIImage(named: "defaultCheckbox")
@ -19,20 +19,21 @@ class SideMenuViewController: UIViewController {
var sideMenuDidHide: SideMenuHandler?
@IBOutlet private weak var shadowView: UIView!
@IBOutlet private weak var menuTableView: UITableView!
@IBOutlet private weak var menuTableViewWidthConstraint: NSLayoutConstraint!
@IBOutlet fileprivate weak var shadowView: UIView!
@IBOutlet fileprivate weak var menuTableView: UITableView!
@IBOutlet fileprivate weak var menuTableViewWidthConstraint: NSLayoutConstraint!
private var menuItems = SegmentioStyle.allStyles
private var currentStyle = SegmentioStyle.OnlyImage
fileprivate var menuItems = SegmentioStyle.allStyles
fileprivate var currentStyle = SegmentioStyle.onlyImage
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
menuTableView.hidden = true
view.hidden = true
menuTableViewWidthConstraint.constant = UIScreen.mainScreen().bounds.width * 0.7
menuTableView.isHidden = true
view.isHidden = true
menuTableViewWidthConstraint.constant = UIScreen.main.bounds.width * 0.7
setupGestureRecognizers()
}
@ -40,23 +41,24 @@ class SideMenuViewController: UIViewController {
class func create() -> SideMenuViewController {
let board = UIStoryboard(name: "Main", bundle: nil)
return board.instantiateViewControllerWithIdentifier(String(self)) as! SideMenuViewController
return board.instantiateViewController(withIdentifier: String(describing: self)) as! SideMenuViewController
}
func showSideMenu(viewController viewController: UIViewController, currentStyle: SegmentioStyle, sideMenuDidHide: SideMenuHandler?) {
func showSideMenu(viewController: UIViewController, currentStyle: SegmentioStyle, sideMenuDidHide: SideMenuHandler?) {
self.currentStyle = currentStyle
self.sideMenuDidHide = sideMenuDidHide
self.modalPresentationStyle = .OverCurrentContext
modalPresentationStyle = .overCurrentContext
let size = view.frame.size
viewController.presentViewController(self, animated: false) { [weak self] in
self?.view.hidden = false
viewController.present(self, animated: false) { [weak self] in
self?.view.isHidden = false
self?.menuTableView.frame.origin = CGPoint(x: -size.width, y: 0)
UIView.animateWithDuration(
animationDuration,
UIView.animate(
withDuration: animationDuration,
animations: {
self?.view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.63)
self?.slideAnimationToPoint(CGPointZero)
self?.menuTableView.hidden = false
self?.view.backgroundColor = UIColor.black.withAlphaComponent(0.63)
self?.slideAnimationToPoint(.zero)
self?.menuTableView.isHidden = false
}
)
}
@ -64,64 +66,55 @@ class SideMenuViewController: UIViewController {
// MARK: - Private functions
private func setupGestureRecognizers() {
let dissmisSideMenuSelector = #selector(SideMenuViewController.dissmisSideMenu)
fileprivate func setupGestureRecognizers() {
let dissmisSideMenuSelector = #selector(SideMenuViewController.dismissSideMenu)
let tapRecognizer = UITapGestureRecognizer(
target: self,
action: dissmisSideMenuSelector
)
let tapRecognizer = UITapGestureRecognizer(target: self, action: dissmisSideMenuSelector)
tapRecognizer.delegate = self
shadowView.addGestureRecognizer(tapRecognizer)
let swipeRecognizer = UISwipeGestureRecognizer(
target: self,
action: dissmisSideMenuSelector
)
swipeRecognizer.direction = .Left
let swipeRecognizer = UISwipeGestureRecognizer(target: self, action: dissmisSideMenuSelector)
swipeRecognizer.direction = .left
swipeRecognizer.delegate = self
view.addGestureRecognizer(swipeRecognizer)
}
private func didSelectItemAtIndexPath(indexPath: NSIndexPath) {
fileprivate func didSelectItem(at indexPath: IndexPath) {
currentStyle = SegmentioStyle.allStyles[indexPath.row]
dissmisSideMenu()
dismissSideMenu()
}
@objc private func dissmisSideMenu() {
@objc fileprivate func dismissSideMenu() {
let size = view.frame.size
UIView.animateWithDuration(
animationDuration,
UIView.animate(
withDuration: animationDuration,
animations: {
self.slideAnimationToPoint(CGPoint(x: -size.width, y: 0))
self.view.backgroundColor = UIColor.clearColor()
self.view.backgroundColor = .clear
},
completion: { _ in
self.view.hidden = true
self.menuTableView.hidden = true
self.sideMenuDidHide?(style: self.currentStyle)
self.view.isHidden = true
self.menuTableView.isHidden = true
self.sideMenuDidHide?(self.currentStyle)
}
)
}
private func slideAnimationToPoint(point: CGPoint) {
UIView.animateWithDuration(animationDuration) {
fileprivate func slideAnimationToPoint(_ point: CGPoint) {
UIView.animate(withDuration: animationDuration) {
self.menuTableView.frame.origin = point
}
}
private func uncheckCurrentStyle() {
guard let currentStyleIndex = menuItems.indexOf(currentStyle) else {
fileprivate func uncheckCurrentStyle() {
guard let currentStyleIndex = menuItems.index(of: currentStyle) else {
return
}
let activeIndexPath = NSIndexPath(
forRow: currentStyleIndex,
inSection: menuTableView.numberOfSections - 1
)
let activeIndexPath = IndexPath(row: currentStyleIndex, section: menuTableView.numberOfSections - 1)
let activeCell = menuTableView.cellForRowAtIndexPath(activeIndexPath)
let activeCell = menuTableView.cellForRow(at: activeIndexPath)
activeCell?.imageView?.image = defaultCheckboxImage
}
@ -129,45 +122,44 @@ class SideMenuViewController: UIViewController {
extension SideMenuViewController: UITableViewDataSource {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return menuItems.count ?? 0
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return menuItems.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let reuseIdentifier = "Cell"
let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
let isCurrentStyle = currentStyle == menuItems[indexPath.row]
cell!.textLabel?.text = menuItems[indexPath.row].rawValue.stringFromCamelCase()
cell!.imageView?.image = isCurrentStyle ? selectedCheckboxImage : defaultCheckboxImage
cell.textLabel?.text = menuItems[indexPath.row].rawValue.stringFromCamelCase()
cell.imageView?.image = isCurrentStyle ? selectedCheckboxImage : defaultCheckboxImage
return cell!
return cell
}
}
extension SideMenuViewController: UITableViewDelegate {
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
if currentStyle != menuItems[indexPath.row] {
uncheckCurrentStyle()
cell?.imageView?.image = selectedCheckboxImage
}
didSelectItemAtIndexPath(indexPath)
didSelectItem(at: indexPath)
}
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
}
extension SideMenuViewController: UIGestureRecognizerDelegate {
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
}
}

View File

@ -9,7 +9,9 @@ Check this <a href="https://dribbble.com/shots/2820372-Segmentio-Component">proj
##Requirements
iOS 8.x, Swift 2.2.x
- Xcode 8
- iOS 8.x+
- Swift 3
##Installation
@ -17,14 +19,14 @@ iOS 8.x, Swift 2.2.x
```ruby
use_frameworks!
pod 'Segmentio', '~> 1.1.1'
pod 'Segmentio', '~> 2.0'
```
*(CocoaPods v1.0.1 or later required. See [this blog post](http://blog.cocoapods.org/Pod-Authors-Guide-to-CocoaPods-Frameworks/) for details.)*
*CocoaPods v1.1.0 or later required*
####[Carthage](http://github.com/Carthage/Carthage)
```ruby
github "Yalantis/Segmentio" ~> 1.1.1
github "Yalantis/Segmentio" ~> 2.0
```
##Usage
@ -35,6 +37,7 @@ import Segmentio
####Init
You can initialize a `Segmentio` instance from code:
```swift
var segmentioView: Segmentio!
@ -42,9 +45,11 @@ let segmentioViewRect = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.w
segmentioView = Segmentio(frame: segmentioViewRect)
view.addSubview(segmentioView)
```
or
add a `UIView` instance in your .storyboard or .xib, set `Segmentio` class and connect `IBOutlet`:
```swift
@IBOutlet weak var segmentioView: Segmentio!
```
@ -71,6 +76,7 @@ segmentioView.setupContent(
####Configuring items
In order to set items you need to create an array of `SegmentioItem` instances:
```swift
var content = [SegmentioItem]()
@ -83,11 +89,13 @@ content.append(tornadoItem)
####Handling selection
You can specify selected item manually:
```swift
segmentioView.selectedSegmentIndex = 0
```
####Handling callback
```swift
segmentioView.valueDidChange = { segmentio, segmentIndex in
print("Selected item: ", segmentIndex)
@ -96,6 +104,7 @@ segmentioView.valueDidChange = { segmentio, segmentIndex in
####Customization
`Segmentio` can be customized by passing an instance of `SegmentioOptions` struct:
```swift
SegmentioOptions(
backgroundColor: UIColor.whiteColor(),
@ -111,6 +120,7 @@ SegmentioOptions(
```
Selection indicator can be customized by passing an instance of `SegmentioIndicatorOptions`:
```swift
SegmentioIndicatorOptions(
type: .Bottom,
@ -121,6 +131,7 @@ SegmentioIndicatorOptions(
```
Horizontal borders can be customized by passing an instance of `SegmentioHorizontalSeparatorOptions`:
```swift
SegmentioHorizontalSeparatorOptions(
type: SegmentioHorizontalSeparatorType.TopAndBottom, // Top, Bottom, TopAndBottom
@ -130,6 +141,7 @@ SegmentioHorizontalSeparatorOptions(
```
Separators between segments can be customized by passing an instance of `SegmentioVerticalSeparatorOptions`:
```swift
SegmentioVerticalSeparatorOptions(
ratio: 0.6 // from 0.1 to 1
@ -138,6 +150,7 @@ SegmentioVerticalSeparatorOptions(
```
In order to set `SegmentioStates` you need to create a tuple of `SegmentioState` instances:
```swift
SegmentioStates(
defaultState: segmentioState(

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "Segmentio"
spec.version = "1.1.3"
spec.version = "2.0"
spec.homepage = "https://github.com/Yalantis/Segmentio"
spec.summary = "Animated top/bottom segmented control written in Swift!"
@ -10,9 +10,7 @@ Pod::Spec.new do |spec|
spec.license = { :type => "MIT", :file => "LICENSE" }
spec.social_media_url = "https://twitter.com/yalantis"
spec.platform = :ios, '8.0'
spec.ios.deployment_target = '8.0'
spec.source = { :git => "https://github.com/Yalantis/Segmentio.git", :tag => spec.version }
spec.source_files = 'Segmentio/Source/**/*.swift'

View File

@ -18,6 +18,10 @@
324B605E1D33E5200050B083 /* UIView+Appearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 324B60541D33E5200050B083 /* UIView+Appearance.swift */; };
324B605F1D33E5200050B083 /* Segmentio.swift in Sources */ = {isa = PBXBuildFile; fileRef = 324B60551D33E5200050B083 /* Segmentio.swift */; };
324B60601D33E5200050B083 /* SegmentioOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 324B60561D33E5200050B083 /* SegmentioOptions.swift */; };
C5514DD81DAB5B82008F14AA /* BadgeViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5514DD31DAB5B82008F14AA /* BadgeViewPresenter.swift */; };
C5514DD91DAB5B82008F14AA /* BadgeWithCounterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5514DD51DAB5B82008F14AA /* BadgeWithCounterView.swift */; };
C5514DDA1DAB5B82008F14AA /* BadgeWithCounterViewBigSized.xib in Resources */ = {isa = PBXBuildFile; fileRef = C5514DD61DAB5B82008F14AA /* BadgeWithCounterViewBigSized.xib */; };
C5514DDB1DAB5B82008F14AA /* BadgeWithCounterViewStandardSized.xib in Resources */ = {isa = PBXBuildFile; fileRef = C5514DD71DAB5B82008F14AA /* BadgeWithCounterViewStandardSized.xib */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -34,6 +38,10 @@
324B60541D33E5200050B083 /* UIView+Appearance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Appearance.swift"; sourceTree = "<group>"; };
324B60551D33E5200050B083 /* Segmentio.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Segmentio.swift; sourceTree = "<group>"; };
324B60561D33E5200050B083 /* SegmentioOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SegmentioOptions.swift; sourceTree = "<group>"; };
C5514DD31DAB5B82008F14AA /* BadgeViewPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BadgeViewPresenter.swift; sourceTree = "<group>"; };
C5514DD51DAB5B82008F14AA /* BadgeWithCounterView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BadgeWithCounterView.swift; sourceTree = "<group>"; };
C5514DD61DAB5B82008F14AA /* BadgeWithCounterViewBigSized.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BadgeWithCounterViewBigSized.xib; sourceTree = "<group>"; };
C5514DD71DAB5B82008F14AA /* BadgeWithCounterViewStandardSized.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BadgeWithCounterViewStandardSized.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -76,6 +84,7 @@
324B604A1D33E5200050B083 /* Source */ = {
isa = PBXGroup;
children = (
C5514DD21DAB5B82008F14AA /* Badge */,
324B604B1D33E5200050B083 /* Cells */,
324B60531D33E5200050B083 /* Extensions */,
324B60551D33E5200050B083 /* Segmentio.swift */,
@ -106,6 +115,25 @@
path = Extensions;
sourceTree = "<group>";
};
C5514DD21DAB5B82008F14AA /* Badge */ = {
isa = PBXGroup;
children = (
C5514DD31DAB5B82008F14AA /* BadgeViewPresenter.swift */,
C5514DD41DAB5B82008F14AA /* Views */,
);
path = Badge;
sourceTree = "<group>";
};
C5514DD41DAB5B82008F14AA /* Views */ = {
isa = PBXGroup;
children = (
C5514DD51DAB5B82008F14AA /* BadgeWithCounterView.swift */,
C5514DD61DAB5B82008F14AA /* BadgeWithCounterViewBigSized.xib */,
C5514DD71DAB5B82008F14AA /* BadgeWithCounterViewStandardSized.xib */,
);
path = Views;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
@ -150,6 +178,7 @@
TargetAttributes = {
324B603F1D33E43E0050B083 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0800;
};
};
};
@ -176,6 +205,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C5514DDB1DAB5B82008F14AA /* BadgeWithCounterViewStandardSized.xib in Resources */,
C5514DDA1DAB5B82008F14AA /* BadgeWithCounterViewBigSized.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -189,6 +220,8 @@
324B60601D33E5200050B083 /* SegmentioOptions.swift in Sources */,
324B605B1D33E5200050B083 /* SegmentioCellWithImageOverLabel.swift in Sources */,
324B60571D33E5200050B083 /* SegmentioCell.swift in Sources */,
C5514DD91DAB5B82008F14AA /* BadgeWithCounterView.swift in Sources */,
C5514DD81DAB5B82008F14AA /* BadgeViewPresenter.swift in Sources */,
324B60591D33E5200050B083 /* SegmentioCellWithImageAfterLabel.swift in Sources */,
324B605F1D33E5200050B083 /* Segmentio.swift in Sources */,
324B60581D33E5200050B083 /* SegmentioCellWithImage.swift in Sources */,
@ -301,6 +334,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.yalantismobile.Segmentio;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
@ -320,6 +354,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.yalantismobile.Segmentio;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};

View File

@ -10,12 +10,7 @@ import UIKit
class BadgeViewPresenter {
func addBadgeForContainerView(
containerView: UIView,
counterValue: Int,
backgroundColor: UIColor = .redColor(),
badgeSize: CounterBadgeSize = .Standard
) {
func addBadgeForContainerView(_ containerView: UIView, counterValue: Int, backgroundColor: UIColor = .red, badgeSize: BadgeSize = .standard) {
var badgeView: BadgeWithCounterView!
for view in containerView.subviews {
if view is BadgeWithCounterView {
@ -25,19 +20,15 @@ class BadgeViewPresenter {
}
}
if badgeView == nil {
badgeView = badgeViewForCounterValue(
counterValue,
backgroundColor: backgroundColor,
size: badgeSize
)
badgeView = badgeViewForCounterValue(counterValue, backgroundColor: backgroundColor, size: badgeSize)
badgeView.translatesAutoresizingMaskIntoConstraints = false
containerView.addSubview(badgeView)
containerView.bringSubviewToFront(badgeView)
containerView.bringSubview(toFront: badgeView)
setupBadgeConstraints(badgeView, counterValue: counterValue)
}
}
func removeBadgeFromContainerView(containerView: UIView) {
func removeBadgeFromContainerView(_ containerView: UIView) {
for view in containerView.subviews {
if view is BadgeWithCounterView {
view.removeFromSuperview()
@ -45,7 +36,7 @@ class BadgeViewPresenter {
}
}
private func setupBadgeConstraints(badgeView: BadgeWithCounterView, counterValue: Int) {
fileprivate func setupBadgeConstraints(_ badgeView: BadgeWithCounterView, counterValue: Int) {
var constraintConstant:CGFloat = -5.0
if counterValue > 9 {
constraintConstant = -10.0
@ -53,10 +44,10 @@ class BadgeViewPresenter {
let segmentTitleLabelHorizontalCenterConstraint =
NSLayoutConstraint(
item: badgeView,
attribute: .Top,
relatedBy: .Equal,
attribute: .top,
relatedBy: .equal,
toItem: badgeView.superview,
attribute: .Top,
attribute: .top,
multiplier: 1,
constant: 6.0
)
@ -64,28 +55,38 @@ class BadgeViewPresenter {
let segmentTitleLabelVerticalCenterConstraint =
NSLayoutConstraint(
item: badgeView,
attribute: .Trailing,
relatedBy: .Equal,
attribute: .trailing,
relatedBy: .equal,
toItem: badgeView.superview,
attribute: .Trailing,
attribute: .trailing,
multiplier: 1,
constant: constraintConstant
)
segmentTitleLabelHorizontalCenterConstraint.active = true
segmentTitleLabelVerticalCenterConstraint.active = true
segmentTitleLabelHorizontalCenterConstraint.isActive = true
segmentTitleLabelVerticalCenterConstraint.isActive = true
}
}
enum Separator {
case top
case bottom
case topAndBottom
}
// MARK: Badges views creation
extension BadgeViewPresenter {
private func badgeViewForCounterValue(counter: Int, backgroundColor: UIColor, size: CounterBadgeSize) -> BadgeWithCounterView {
fileprivate func badgeViewForCounterValue(_ counter: Int, backgroundColor: UIColor, size: BadgeSize) -> BadgeWithCounterView {
let view = BadgeWithCounterView.instanceFromNib(size: size)
view.setBadgeBackgroundColor(backgroundColor)
view.setBadgeCounterValue(counter)
return view
}
}
}

View File

@ -5,27 +5,29 @@ private let BadgeCounterOverMaxValueText = "99+"
private let standardSizedNibName = "BadgeWithCounterViewStandardSized"
private let bigSizedNibName = "BadgeWithCounterViewBigSized"
enum CounterBadgeSize {
case Standard
case Big
enum BadgeSize {
case standard
case big
}
class BadgeWithCounterView: UIView {
@IBOutlet private weak var counterValueLabel: UILabel!
@IBOutlet private weak var backgroundImageView: UIImageView!
@IBOutlet fileprivate weak var counterValueLabel: UILabel!
@IBOutlet fileprivate weak var backgroundImageView: UIImageView!
class func instanceFromNib(size size: CounterBadgeSize) -> BadgeWithCounterView {
class func instanceFromNib(size: BadgeSize) -> BadgeWithCounterView {
let nibName = nibNameForSize(size)
let podBundle = NSBundle(forClass: self.classForCoder())
let podBundle = Bundle(for: self.classForCoder())
if let bundleURL = podBundle.URLForResource("Segmentio", withExtension: "bundle"), bundle = NSBundle(URL: bundleURL) {
return UINib(nibName: nibName, bundle: bundle).instantiateWithOwner(nil, options: nil)[0] as! BadgeWithCounterView
if let bundleURL = podBundle.url(forResource: "Segmentio", withExtension: "bundle"), let bundle = Bundle(url: bundleURL) {
return UINib(nibName: nibName, bundle: bundle).instantiate(withOwner: nil, options: nil)[0] as! BadgeWithCounterView
}
return BadgeWithCounterView(frame: CGRectZero)
return BadgeWithCounterView(frame: .zero)
}
func setBadgeCounterValue(counterValue: Int) {
func setBadgeCounterValue(_ counterValue: Int) {
var counterText: String!
if counterValue > BadgeCounterMaxValue {
counterText = BadgeCounterOverMaxValueText
@ -35,12 +37,11 @@ class BadgeWithCounterView: UIView {
counterValueLabel.text = counterText
}
func setBadgeBackgroundColor(color: UIColor) {
func setBadgeBackgroundColor(_ color: UIColor) {
backgroundImageView.backgroundColor = color
}
private class func nibNameForSize(size: CounterBadgeSize) -> String {
return (size == .Standard) ? standardSizedNibName : bigSizedNibName
fileprivate class func nibNameForSize(_ size: BadgeSize) -> String {
return size == .standard ? standardSizedNibName : bigSizedNibName
}
}
}

View File

@ -23,19 +23,19 @@ class SegmentioCell: UICollectionViewCell {
var bottomConstraint: NSLayoutConstraint?
var cellSelected = false
private var options = SegmentioOptions()
private var style = SegmentioStyle.ImageOverLabel
private let verticalSeparatorLayer = CAShapeLayer()
private let badgePresenter = BadgeViewPresenter()
fileprivate var options = SegmentioOptions()
fileprivate var style = SegmentioStyle.imageOverLabel
fileprivate let verticalSeparatorLayer = CAShapeLayer()
fileprivate let badgePresenter = BadgeViewPresenter()
override var highlighted: Bool {
override var isHighlighted: Bool {
get {
return super.highlighted
return super.isHighlighted
}
set {
if newValue != highlighted {
super.highlighted = newValue
if newValue != isHighlighted {
super.isHighlighted = newValue
let highlightedState = options.states.highlightedState
let defaultState = options.states.defaultState
@ -45,11 +45,11 @@ class SegmentioCell: UICollectionViewCell {
let highlightedTitleTextColor = cellSelected ? selectedState.titleTextColor : defaultState.titleTextColor
let highlightedTitleFont = cellSelected ? selectedState.titleFont : defaultState.titleFont
segmentTitleLabel?.textColor = highlighted ? highlightedState.titleTextColor : highlightedTitleTextColor
segmentTitleLabel?.font = highlighted ? highlightedState.titleFont : highlightedTitleFont
segmentTitleLabel?.textColor = isHighlighted ? highlightedState.titleTextColor : highlightedTitleTextColor
segmentTitleLabel?.font = isHighlighted ? highlightedState.titleFont : highlightedTitleFont
}
backgroundColor = highlighted ? highlightedState.backgroundColor : defaultState.backgroundColor
backgroundColor = isHighlighted ? highlightedState.backgroundColor : defaultState.backgroundColor
}
}
}
@ -58,23 +58,23 @@ class SegmentioCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
imageContainerView = UIView(frame: CGRectZero)
imageContainerView = UIView(frame: CGRect.zero)
if let imageContainerView = imageContainerView {
contentView.addSubview(imageContainerView)
}
segmentImageView = UIImageView(frame: CGRectZero)
if let segmentImageView = segmentImageView, imageContainerView = imageContainerView {
segmentImageView = UIImageView(frame: CGRect.zero)
if let segmentImageView = segmentImageView, let imageContainerView = imageContainerView {
imageContainerView.addSubview(segmentImageView)
}
containerView = UIView(frame: CGRectZero)
containerView = UIView(frame: CGRect.zero)
if let containerView = containerView {
contentView.addSubview(containerView)
}
segmentTitleLabel = UILabel(frame: CGRectZero)
if let segmentTitleLabel = segmentTitleLabel, containerView = containerView {
segmentTitleLabel = UILabel(frame: CGRect.zero)
if let segmentTitleLabel = segmentTitleLabel, let containerView = containerView {
containerView.addSubview(segmentTitleLabel)
}
@ -84,7 +84,7 @@ class SegmentioCell: UICollectionViewCell {
imageContainerView?.translatesAutoresizingMaskIntoConstraints = false
segmentImageView?.layer.masksToBounds = true
segmentTitleLabel?.font = UIFont.systemFontOfSize(UIFont.smallSystemFontSize())
segmentTitleLabel?.font = UIFont.systemFont(ofSize: UIFont.smallSystemFontSize)
setupConstraintsForSubviews()
addVerticalSeparator()
@ -99,10 +99,10 @@ class SegmentioCell: UICollectionViewCell {
super.prepareForReuse()
switch style {
case .OnlyLabel:
case .onlyLabel:
badgePresenter.removeBadgeFromContainerView(containerView!)
segmentTitleLabel?.text = nil
case .OnlyImage:
case .onlyImage:
badgePresenter.removeBadgeFromContainerView(imageContainerView!)
segmentImageView?.image = nil
default:
@ -114,7 +114,7 @@ class SegmentioCell: UICollectionViewCell {
// MARK: - Configure
func configure(content content: SegmentioItem, style: SegmentioStyle, options: SegmentioOptions, isLastCell: Bool) {
func configure(content: SegmentioItem, style: SegmentioStyle, options: SegmentioOptions, isLastCell: Bool) {
self.options = options
self.style = style
setupContent(content: content)
@ -130,7 +130,7 @@ class SegmentioCell: UICollectionViewCell {
configurateBadgeWithCount(content.badgeCount, color: content.badgeColor)
}
func configure(selected selected: Bool) {
func configure(selected: Bool) {
cellSelected = selected
let selectedState = options.states.selectedState
@ -142,24 +142,24 @@ class SegmentioCell: UICollectionViewCell {
}
}
func configurateBadgeWithCount(badgeCount: Int?, color: UIColor?) {
guard let badgeCount = badgeCount, color = color else {
func configurateBadgeWithCount(_ badgeCount: Int?, color: UIColor?) {
guard let badgeCount = badgeCount, let color = color else {
return
}
if style == .OnlyImage {
if style == .onlyImage {
badgePresenter.addBadgeForContainerView(
imageContainerView!,
counterValue: badgeCount,
backgroundColor: color,
badgeSize: .Standard
badgeSize: .standard
)
} else {
badgePresenter.addBadgeForContainerView(
containerView!,
counterValue: badgeCount,
backgroundColor: color,
badgeSize: .Standard
badgeSize: .standard
)
}
}
@ -172,7 +172,7 @@ class SegmentioCell: UICollectionViewCell {
// MARK: - Private functions
private func setupContainerConstraints() {
fileprivate func setupContainerConstraints() {
guard let segmentTitleLabel = segmentTitleLabel else {
return
}
@ -183,10 +183,10 @@ class SegmentioCell: UICollectionViewCell {
let segmentTitleLabelHorizontalCenterConstraint =
NSLayoutConstraint(
item: segmentTitleLabel,
attribute: .CenterX,
relatedBy: .Equal,
attribute: .centerX,
relatedBy: .equal,
toItem: containerView,
attribute: .CenterX,
attribute: .centerX,
multiplier: 1,
constant: 0.0
)
@ -194,17 +194,17 @@ class SegmentioCell: UICollectionViewCell {
let segmentTitleLabelVerticalCenterConstraint =
NSLayoutConstraint(
item: segmentTitleLabel,
attribute: .CenterY,
relatedBy: .Equal,
attribute: .centerY,
relatedBy: .equal,
toItem: containerView,
attribute: .CenterY,
attribute: .centerY,
multiplier: 1,
constant: 0.0
)
addConstraints([segmentTitleLabelHorizontalCenterConstraint, segmentTitleLabelVerticalCenterConstraint])
}
private func setupImageContainerConstraints() {
fileprivate func setupImageContainerConstraints() {
guard let segmentImageView = segmentImageView else {
return
}
@ -215,10 +215,10 @@ class SegmentioCell: UICollectionViewCell {
let segmentImageViewTopConstraint =
NSLayoutConstraint(
item: segmentImageView,
attribute: .Top,
relatedBy: .Equal,
attribute: .top,
relatedBy: .equal,
toItem: imageContainerView,
attribute: .Top,
attribute: .top,
multiplier: 1,
constant: 0.0
)
@ -226,10 +226,10 @@ class SegmentioCell: UICollectionViewCell {
let segmentImageViewLeadingConstraint =
NSLayoutConstraint(
item: segmentImageView,
attribute: .Leading,
relatedBy: .Equal,
attribute: .leading,
relatedBy: .equal,
toItem: imageContainerView,
attribute: .Leading,
attribute: .leading,
multiplier: 1,
constant: 0.0
)
@ -237,10 +237,10 @@ class SegmentioCell: UICollectionViewCell {
let segmentImageViewTrailingConstraint =
NSLayoutConstraint(
item: segmentImageView,
attribute: .Trailing,
relatedBy: .Equal,
attribute: .trailing,
relatedBy: .equal,
toItem: imageContainerView,
attribute: .Trailing,
attribute: .trailing,
multiplier: 1,
constant: 0.0
)
@ -248,10 +248,10 @@ class SegmentioCell: UICollectionViewCell {
let segmentImageViewBottomConstraint =
NSLayoutConstraint(
item: segmentImageView,
attribute: .Bottom,
relatedBy: .Equal,
attribute: .bottom,
relatedBy: .equal,
toItem: imageContainerView,
attribute: .Bottom,
attribute: .bottom,
multiplier: 1,
constant: 0.0
)
@ -259,7 +259,7 @@ class SegmentioCell: UICollectionViewCell {
}
private func setupContent(content content: SegmentioItem) {
fileprivate func setupContent(content: SegmentioItem) {
if style.isWithImage() {
segmentImageView?.contentMode = options.imageContentMode
segmentImageView?.image = content.image
@ -274,18 +274,18 @@ class SegmentioCell: UICollectionViewCell {
}
}
private func setupConstraint(indicatorOptions indicatorOptions: SegmentioIndicatorOptions) {
fileprivate func setupConstraint(indicatorOptions: SegmentioIndicatorOptions) {
switch indicatorOptions.type {
case .Top:
case .top:
topConstraint?.constant = padding + indicatorOptions.height
case .Bottom:
case .bottom:
bottomConstraint?.constant = padding + indicatorOptions.height
}
}
// MARK: - Vertical separator
private func addVerticalSeparator() {
fileprivate func addVerticalSeparator() {
let contentViewWidth = contentView.bounds.width
let rect = CGRect(
x: contentView.bounds.width - 1,
@ -311,50 +311,50 @@ class SegmentioCell: UICollectionViewCell {
let widthConstraint = NSLayoutConstraint(
item: verticalSeparatorView,
attribute: .Width,
relatedBy: .Equal,
attribute: .width,
relatedBy: .equal,
toItem: nil,
attribute: .NotAnAttribute,
attribute: .notAnAttribute,
multiplier: 1,
constant: 1
)
widthConstraint.active = true
widthConstraint.isActive = true
let trailingConstraint = NSLayoutConstraint(
item: verticalSeparatorView,
attribute: .Trailing,
relatedBy: .Equal,
attribute: .trailing,
relatedBy: .equal,
toItem: contentView,
attribute: .Trailing,
attribute: .trailing,
multiplier: 1,
constant: 0
)
trailingConstraint.active = true
trailingConstraint.isActive = true
let topConstraint = NSLayoutConstraint(
item: verticalSeparatorView,
attribute: .Top,
relatedBy: .Equal,
attribute: .top,
relatedBy: .equal,
toItem: contentView,
attribute: .Top,
attribute: .top,
multiplier: 1,
constant: 0
)
topConstraint.active = true
topConstraint.isActive = true
let bottomConstraint = NSLayoutConstraint(
item: contentView,
attribute: .Bottom,
relatedBy: .Equal,
attribute: .bottom,
relatedBy: .equal,
toItem: verticalSeparatorView,
attribute: .Bottom,
attribute: .bottom,
multiplier: 1,
constant: 0
)
bottomConstraint.active = true
bottomConstraint.isActive = true
}
private func setupVerticalSeparators() {
fileprivate func setupVerticalSeparators() {
guard let verticalSeparatorOptions = options.verticalSeparatorOptions else {
return
}
@ -370,15 +370,15 @@ class SegmentioCell: UICollectionViewCell {
let endY = bounds.height - difference
let path = UIBezierPath()
path.moveToPoint(CGPoint(x: verticalSeparatorView.frame.width / 2, y: startY))
path.addLineToPoint(CGPoint(x: verticalSeparatorView.frame.width / 2, y: endY))
path.move(to: CGPoint(x: verticalSeparatorView.frame.width / 2, y: startY))
path.addLine(to: CGPoint(x: verticalSeparatorView.frame.width / 2, y: endY))
verticalSeparatorLayer.path = path.CGPath
verticalSeparatorLayer.path = path.cgPath
verticalSeparatorLayer.lineWidth = 1
verticalSeparatorLayer.strokeColor = verticalSeparatorOptions.color.CGColor
verticalSeparatorLayer.fillColor = verticalSeparatorOptions.color.CGColor
verticalSeparatorLayer.strokeColor = verticalSeparatorOptions.color.cgColor
verticalSeparatorLayer.fillColor = verticalSeparatorOptions.color.cgColor
verticalSeparatorView.layer.addSublayer(verticalSeparatorLayer)
}
}
}

View File

@ -20,36 +20,36 @@ final class SegmentioCellWithImage: SegmentioCell {
// main constraints
let segmentImageViewlHorizontConstraint = NSLayoutConstraint.constraintsWithVisualFormat(
"|-[imageContainerView]-|",
let segmentImageViewlHorizontConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "|-[imageContainerView]-|",
options: [],
metrics: nil,
views: views)
NSLayoutConstraint.activateConstraints(segmentImageViewlHorizontConstraint)
NSLayoutConstraint.activate(segmentImageViewlHorizontConstraint)
// custom constraints
topConstraint = NSLayoutConstraint(
item: imageContainerView,
attribute: .Top,
relatedBy: .Equal,
attribute: .top,
relatedBy: .equal,
toItem: contentView,
attribute: .Top,
attribute: .top,
multiplier: 1,
constant: padding
)
topConstraint?.active = true
topConstraint?.isActive = true
bottomConstraint = NSLayoutConstraint(
item: contentView,
attribute: .Bottom,
relatedBy: .Equal,
attribute: .bottom,
relatedBy: .equal,
toItem: imageContainerView,
attribute: .Bottom,
attribute: .bottom,
multiplier: 1,
constant: padding
)
bottomConstraint?.active = true
bottomConstraint?.isActive = true
}
}
}

View File

@ -27,42 +27,42 @@ final class SegmentioCellWithImageAfterLabel: SegmentioCell {
// main constraints
let segmentImageViewVerticalConstraint = NSLayoutConstraint.constraintsWithVisualFormat(
"V:[imageContainerView(labelHeight)]",
options: [.AlignAllCenterY],
let segmentImageViewVerticalConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "V:[imageContainerView(labelHeight)]",
options: [.alignAllCenterY],
metrics: metrics,
views: views)
NSLayoutConstraint.activateConstraints(segmentImageViewVerticalConstraint)
NSLayoutConstraint.activate(segmentImageViewVerticalConstraint)
let contentViewHorizontalConstraints = NSLayoutConstraint.constraintsWithVisualFormat(
"|-[containerView]-[imageContainerView(labelHeight)]-|",
options: [.AlignAllCenterY],
let contentViewHorizontalConstraints = NSLayoutConstraint.constraints(
withVisualFormat: "|-[containerView]-[imageContainerView(labelHeight)]-|",
options: [.alignAllCenterY],
metrics: metrics,
views: views)
NSLayoutConstraint.activateConstraints(contentViewHorizontalConstraints)
NSLayoutConstraint.activate(contentViewHorizontalConstraints)
// custom constraints
topConstraint = NSLayoutConstraint(
item: containerView,
attribute: .Top,
relatedBy: .Equal,
attribute: .top,
relatedBy: .equal,
toItem: contentView,
attribute: .Top,
attribute: .top,
multiplier: 1,
constant: padding
)
topConstraint?.active = true
topConstraint?.isActive = true
bottomConstraint = NSLayoutConstraint(
item: contentView,
attribute: .Bottom,
relatedBy: .Equal,
attribute: .bottom,
relatedBy: .equal,
toItem: containerView,
attribute: .Bottom,
attribute: .bottom,
multiplier: 1,
constant: padding
)
bottomConstraint?.active = true
bottomConstraint?.isActive = true
}
}
}

View File

@ -27,43 +27,43 @@ class SegmentioCellWithImageBeforeLabel: SegmentioCell {
// main constraints
let segmentImageViewVerticalConstraint = NSLayoutConstraint.constraintsWithVisualFormat(
"V:[imageContainerView(labelHeight)]",
options: [.AlignAllCenterY],
let segmentImageViewVerticalConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "V:[imageContainerView(labelHeight)]",
options: [.alignAllCenterY],
metrics: metrics,
views: views)
NSLayoutConstraint.activateConstraints(segmentImageViewVerticalConstraint)
NSLayoutConstraint.activate(segmentImageViewVerticalConstraint)
let contentViewHorizontalConstraints = NSLayoutConstraint.constraintsWithVisualFormat(
"|-[imageContainerView(labelHeight)]-[containerView]-|",
options: [.AlignAllCenterY],
let contentViewHorizontalConstraints = NSLayoutConstraint.constraints(
withVisualFormat: "|-[imageContainerView(labelHeight)]-[containerView]-|",
options: [.alignAllCenterY],
metrics: metrics,
views: views)
NSLayoutConstraint.activateConstraints(contentViewHorizontalConstraints)
NSLayoutConstraint.activate(contentViewHorizontalConstraints)
// custom constraints
topConstraint = NSLayoutConstraint(
item: containerView,
attribute: .Top,
relatedBy: .Equal,
attribute: .top,
relatedBy: .equal,
toItem: contentView,
attribute: .Top,
attribute: .top,
multiplier: 1,
constant: padding
)
topConstraint?.active = true
topConstraint?.isActive = true
bottomConstraint = NSLayoutConstraint(
item: contentView,
attribute: .Bottom,
relatedBy: .Equal,
attribute: .bottom,
relatedBy: .equal,
toItem: containerView,
attribute: .Bottom,
attribute: .bottom,
multiplier: 1,
constant: padding
)
bottomConstraint?.active = true
bottomConstraint?.isActive = true
}
}
}

View File

@ -27,53 +27,53 @@ class SegmentioCellWithImageOverLabel: SegmentioCell {
// main constraints
let segmentImageViewHorizontConstraint = NSLayoutConstraint.constraintsWithVisualFormat(
"|-[imageContainerView]-|",
let segmentImageViewHorizontConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "|-[imageContainerView]-|",
options: [],
metrics: nil,
views: views)
NSLayoutConstraint.activateConstraints(segmentImageViewHorizontConstraint)
NSLayoutConstraint.activate(segmentImageViewHorizontConstraint)
let segmentTitleLabelHorizontConstraint = NSLayoutConstraint.constraintsWithVisualFormat(
"|-[containerView]-|",
options: [.AlignAllCenterX],
let segmentTitleLabelHorizontConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "|-[containerView]-|",
options: [.alignAllCenterX],
metrics: nil,
views: views
)
NSLayoutConstraint.activateConstraints(segmentTitleLabelHorizontConstraint)
NSLayoutConstraint.activate(segmentTitleLabelHorizontConstraint)
let contentViewVerticalConstraints = NSLayoutConstraint.constraintsWithVisualFormat(
"V:[imageContainerView]-[containerView(labelHeight)]",
let contentViewVerticalConstraints = NSLayoutConstraint.constraints(
withVisualFormat: "V:[imageContainerView]-[containerView(labelHeight)]",
options: [],
metrics: metrics,
views: views)
NSLayoutConstraint.activateConstraints(contentViewVerticalConstraints)
NSLayoutConstraint.activate(contentViewVerticalConstraints)
// custom constraints
topConstraint = NSLayoutConstraint(
item: imageContainerView,
attribute: .Top,
relatedBy: .Equal,
attribute: .top,
relatedBy: .equal,
toItem: contentView,
attribute: .Top,
attribute: .top,
multiplier: 1,
constant: padding
)
topConstraint?.active = true
topConstraint?.isActive = true
bottomConstraint = NSLayoutConstraint(
item: contentView,
attribute: .Bottom,
relatedBy: .Equal,
attribute: .bottom,
relatedBy: .equal,
toItem: containerView,
attribute: .Bottom,
attribute: .bottom,
multiplier: 1,
constant: padding
)
bottomConstraint?.active = true
bottomConstraint?.isActive = true
}
}
}

View File

@ -27,51 +27,51 @@ class SegmentioCellWithImageUnderLabel: SegmentioCell {
// main constraints
let segmentImageViewHorizontConstraint = NSLayoutConstraint.constraintsWithVisualFormat(
"|-[imageContainerView]-|",
let segmentImageViewHorizontConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "|-[imageContainerView]-|",
options: [],
metrics: nil,
views: views)
NSLayoutConstraint.activateConstraints(segmentImageViewHorizontConstraint)
NSLayoutConstraint.activate(segmentImageViewHorizontConstraint)
let segmentTitleLabelHorizontConstraint = NSLayoutConstraint.constraintsWithVisualFormat(
"|-[containerView]-|",
options: [.AlignAllCenterX],
let segmentTitleLabelHorizontConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "|-[containerView]-|",
options: [.alignAllCenterX],
metrics: nil,
views: views
)
NSLayoutConstraint.activateConstraints(segmentTitleLabelHorizontConstraint)
NSLayoutConstraint.activate(segmentTitleLabelHorizontConstraint)
let contentViewVerticalConstraints = NSLayoutConstraint.constraintsWithVisualFormat(
"V:[containerView(labelHeight)]-[imageContainerView]",
let contentViewVerticalConstraints = NSLayoutConstraint.constraints(
withVisualFormat: "V:[containerView(labelHeight)]-[imageContainerView]",
options: [],
metrics: metrics,
views: views)
NSLayoutConstraint.activateConstraints(contentViewVerticalConstraints)
NSLayoutConstraint.activate(contentViewVerticalConstraints)
// custom constraints
topConstraint = NSLayoutConstraint(
item: containerView,
attribute: .Top,
relatedBy: .Equal,
attribute: .top,
relatedBy: .equal,
toItem: contentView,
attribute: .Top,
attribute: .top,
multiplier: 1,
constant: padding
)
topConstraint?.active = true
topConstraint?.isActive = true
bottomConstraint = NSLayoutConstraint(
item: contentView,
attribute: .Bottom,
relatedBy: .Equal,
attribute: .bottom,
relatedBy: .equal,
toItem: imageContainerView,
attribute: .Bottom,
attribute: .bottom,
multiplier: 1,
constant: padding
)
bottomConstraint?.active = true
bottomConstraint?.isActive = true
}
}
}

View File

@ -21,37 +21,37 @@ final class SegmentioCellWithLabel: SegmentioCell {
// main constraints
let segmentTitleLabelHorizontConstraint = NSLayoutConstraint.constraintsWithVisualFormat(
"|-[containerView]-|",
options: [.AlignAllCenterX],
let segmentTitleLabelHorizontConstraint = NSLayoutConstraint.constraints(
withVisualFormat: "|-[containerView]-|",
options: [.alignAllCenterX],
metrics: nil,
views: views
)
NSLayoutConstraint.activateConstraints(segmentTitleLabelHorizontConstraint)
NSLayoutConstraint.activate(segmentTitleLabelHorizontConstraint)
// custom constraints
topConstraint = NSLayoutConstraint(
item: containerView,
attribute: .Top,
relatedBy: .Equal,
attribute: .top,
relatedBy: .equal,
toItem: contentView,
attribute: .Top,
attribute: .top,
multiplier: 1,
constant: padding
)
topConstraint?.active = true
topConstraint?.isActive = true
bottomConstraint = NSLayoutConstraint(
item: contentView,
attribute: .Bottom,
relatedBy: .Equal,
attribute: .bottom,
relatedBy: .equal,
toItem: containerView,
attribute: .Bottom,
attribute: .bottom,
multiplier: 1,
constant: padding
)
bottomConstraint?.active = true
bottomConstraint?.isActive = true
}
}
}

View File

@ -15,9 +15,9 @@ class RoundImageView: UIImageView {
updateCornerRadiusValue()
}
private func updateCornerRadiusValue() {
fileprivate func updateCornerRadiusValue() {
let cornerRadius = min(bounds.size.height, bounds.size.width) / 2
layer.cornerRadius = cornerRadius
}
}
}

View File

@ -8,34 +8,40 @@
import UIKit
private typealias SubviewTreeModifier = (Void -> UIView)
private typealias SubviewTreeModifier = ((Void) -> UIView)
public struct AppearanceOptions: OptionSetType {
public struct AppearanceOptions: OptionSet {
public static let overlay = AppearanceOptions(rawValue: 1 << 0)
public static let useAutoresize = AppearanceOptions(rawValue: 1 << 1)
public let rawValue: UInt
public init(rawValue: UInt) { self.rawValue = rawValue }
public static let Overlay = AppearanceOptions(rawValue: 1 << 0)
public static let UseAutoresize = AppearanceOptions(rawValue: 1 << 1)
public init(rawValue: UInt) {
self.rawValue = rawValue
}
}
extension UIView {
private func addSubviewUsingOptions(options: AppearanceOptions, modifier: SubviewTreeModifier) {
fileprivate func addSubviewUsingOptions(_ options: AppearanceOptions, modifier: SubviewTreeModifier) {
let subview = modifier()
if options.union(.Overlay) == .Overlay {
if options.union(.UseAutoresize) != .UseAutoresize {
if options.union(.overlay) == .overlay {
if options.union(.useAutoresize) != .useAutoresize {
subview.translatesAutoresizingMaskIntoConstraints = false
let views = dictionaryOfNames([subview])
let horisontalConstraints = NSLayoutConstraint.constraintsWithVisualFormat(
"|[subview]|",
let horisontalConstraints = NSLayoutConstraint.constraints(
withVisualFormat: "|[subview]|",
options: [],
metrics: nil,
views: views
)
addConstraints(horisontalConstraints)
let verticalConstraints = NSLayoutConstraint.constraintsWithVisualFormat(
"V:|[subview]|",
let verticalConstraints = NSLayoutConstraint.constraints(
withVisualFormat: "V:|[subview]|",
options: [],
metrics: nil,
views: views
@ -44,14 +50,14 @@ extension UIView {
} else {
frame = bounds
subview.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
subview.autoresizingMask = [.flexibleWidth, .flexibleHeight]
}
}
}
private func dictionaryOfNames(views:[UIView]) -> [String: UIView] {
fileprivate func dictionaryOfNames(_ views: [UIView]) -> [String: UIView] {
var container = [String: UIView]()
for (_, value) in views.enumerate() {
for (_, value) in views.enumerated() {
container["subview"] = value
}
return container
@ -59,7 +65,7 @@ extension UIView {
// MARK: - Interface methods
public func addSubview(subview: UIView, options: AppearanceOptions) {
public func addSubview(_ subview: UIView, options: AppearanceOptions) {
if subview.superview == self {
return
}
@ -69,14 +75,14 @@ extension UIView {
}
}
public func insertSubview(subview: UIView, index: Int, options: AppearanceOptions) {
public func insertSubview(_ subview: UIView, index: Int, options: AppearanceOptions) {
if subview.superview == self {
return
}
addSubviewUsingOptions(options) { [weak self] in
self?.insertSubview(subview, atIndex: index)
self?.insertSubview(subview, at: index)
return subview
}
}
}
}

View File

@ -9,11 +9,11 @@
import UIKit
import QuartzCore
public typealias SegmentioSelectionCallback = ((segmentio: Segmentio, selectedSegmentioIndex: Int) -> Void)
public typealias SegmentioSelectionCallback = ((_ segmentio: Segmentio, _ selectedSegmentioIndex: Int) -> Void)
private let animationDuration: CFTimeInterval = 0.3
public class Segmentio: UIView {
open class Segmentio: UIView {
internal struct Points {
var startPoint: CGPoint
@ -36,28 +36,28 @@ public class Segmentio: UIView {
var endX: CGFloat
}
public var valueDidChange: SegmentioSelectionCallback?
public var selectedSegmentioIndex = -1 {
open var valueDidChange: SegmentioSelectionCallback?
open var selectedSegmentioIndex = -1 {
didSet {
if selectedSegmentioIndex != oldValue {
reloadSegmentio()
valueDidChange?(segmentio: self, selectedSegmentioIndex: selectedSegmentioIndex)
valueDidChange?(self, selectedSegmentioIndex)
}
}
}
private var segmentioCollectionView: UICollectionView?
private var segmentioItems = [SegmentioItem]()
private var segmentioOptions = SegmentioOptions()
private var segmentioStyle = SegmentioStyle.ImageOverLabel
private var isPerformingScrollAnimation = false
fileprivate var segmentioCollectionView: UICollectionView?
fileprivate var segmentioItems = [SegmentioItem]()
fileprivate var segmentioOptions = SegmentioOptions()
fileprivate var segmentioStyle = SegmentioStyle.imageOverLabel
fileprivate var isPerformingScrollAnimation = false
private var topSeparatorView: UIView?
private var bottomSeparatorView: UIView?
private var indicatorLayer: CAShapeLayer?
private var selectedLayer: CAShapeLayer?
fileprivate var topSeparatorView: UIView?
fileprivate var bottomSeparatorView: UIView?
fileprivate var indicatorLayer: CAShapeLayer?
fileprivate var selectedLayer: CAShapeLayer?
private var cachedOrientation: UIInterfaceOrientation? = UIApplication.sharedApplication().statusBarOrientation {
fileprivate var cachedOrientation: UIInterfaceOrientation? = UIApplication.shared.statusBarOrientation {
didSet {
if cachedOrientation != oldValue {
reloadSegmentio()
@ -68,7 +68,7 @@ public class Segmentio: UIView {
// MARK: - Lifecycle
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
NotificationCenter.default.removeObserver(self)
}
required public init?(coder aDecoder: NSCoder) {
@ -81,20 +81,20 @@ public class Segmentio: UIView {
commonInit()
}
private func commonInit() {
fileprivate func commonInit() {
setupSegmentedCollectionView()
NSNotificationCenter.defaultCenter().addObserver(
NotificationCenter.default.addObserver(
self,
selector: #selector(Segmentio.handleOrientationNotification),
name: UIDeviceOrientationDidChangeNotification,
name: NSNotification.Name.UIDeviceOrientationDidChange,
object: nil
)
}
private func setupSegmentedCollectionView() {
fileprivate func setupSegmentedCollectionView() {
let layout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsetsZero
layout.scrollDirection = .Horizontal
layout.sectionInset = UIEdgeInsets.zero
layout.scrollDirection = .horizontal
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0
@ -105,21 +105,21 @@ public class Segmentio: UIView {
collectionView.dataSource = self
collectionView.delegate = self
collectionView.pagingEnabled = false
collectionView.isPagingEnabled = false
collectionView.showsHorizontalScrollIndicator = false
collectionView.showsVerticalScrollIndicator = false
collectionView.bounces = true
collectionView.scrollEnabled = segmentioOptions.scrollEnabled
collectionView.backgroundColor = UIColor.clearColor()
collectionView.isScrollEnabled = segmentioOptions.scrollEnabled
collectionView.backgroundColor = .clear
segmentioCollectionView = collectionView
if let segmentioCollectionView = segmentioCollectionView {
addSubview(segmentioCollectionView, options: .Overlay)
addSubview(segmentioCollectionView, options: .overlay)
}
}
private func frameForSegmentCollectionView() -> CGRect {
fileprivate func frameForSegmentCollectionView() -> CGRect {
var separatorsHeight: CGFloat = 0
var collectionViewFrameMinY: CGFloat = 0
@ -127,12 +127,12 @@ public class Segmentio: UIView {
let separatorHeight = horizontalSeparatorOptions.height
switch horizontalSeparatorOptions.type {
case .Top:
case .top:
collectionViewFrameMinY = separatorHeight
separatorsHeight = separatorHeight
case .Bottom:
case .bottom:
separatorsHeight = separatorHeight
case .TopAndBottom:
case .topAndBottom:
collectionViewFrameMinY = separatorHeight
separatorsHeight = separatorHeight * 2
}
@ -148,14 +148,14 @@ public class Segmentio: UIView {
// MARK: - Handle orientation notification
@objc private func handleOrientationNotification() {
cachedOrientation = UIApplication.sharedApplication().statusBarOrientation
@objc fileprivate func handleOrientationNotification() {
cachedOrientation = UIApplication.shared.statusBarOrientation
}
// MARK: - Setups:
// MARK: Main setup
public func setup(content content: [SegmentioItem], style: SegmentioStyle, options: SegmentioOptions?) {
open func setup(content: [SegmentioItem], style: SegmentioStyle, options: SegmentioOptions?) {
segmentioItems = content
segmentioStyle = style
@ -164,13 +164,13 @@ public class Segmentio: UIView {
if let options = options {
segmentioOptions = options
segmentioCollectionView?.scrollEnabled = segmentioOptions.scrollEnabled
segmentioCollectionView?.isScrollEnabled = segmentioOptions.scrollEnabled
backgroundColor = options.backgroundColor
}
if segmentioOptions.states.selectedState.backgroundColor != UIColor.clearColor() {
if segmentioOptions.states.selectedState.backgroundColor != .clear {
selectedLayer = CAShapeLayer()
if let selectedLayer = selectedLayer, sublayer = segmentioCollectionView?.layer {
if let selectedLayer = selectedLayer, let sublayer = segmentioCollectionView?.layer {
setupShapeLayer(
shapeLayer: selectedLayer,
backgroundColor: segmentioOptions.states.selectedState.backgroundColor,
@ -197,43 +197,43 @@ public class Segmentio: UIView {
segmentioCollectionView?.reloadData()
}
public override func didMoveToSuperview() {
open override func didMoveToSuperview() {
super.didMoveToSuperview()
setupHorizontalSeparatorIfPossible()
}
public func setupBadgeAtIndex(index: Int, count: Int, color: UIColor) {
segmentioItems[index].setupBadgeWithCount(count, color: color)
open func addBadge(at index: Int, count: Int, color: UIColor = .red) {
segmentioItems[index].addBadge(count, color: color)
segmentioCollectionView?.reloadData()
}
public func removeBadgeAtIndex(index: Int) {
open func removeBadge(at index: Int) {
segmentioItems[index].removeBadge()
segmentioCollectionView?.reloadData()
}
// MARK: Collection view setup
private func setupCellWithStyle(style: SegmentioStyle) {
fileprivate func setupCellWithStyle(_ style: SegmentioStyle) {
var cellClass: SegmentioCell.Type {
switch style {
case .OnlyLabel:
case .onlyLabel:
return SegmentioCellWithLabel.self
case .OnlyImage:
case .onlyImage:
return SegmentioCellWithImage.self
case .ImageOverLabel:
case .imageOverLabel:
return SegmentioCellWithImageOverLabel.self
case .ImageUnderLabel:
case .imageUnderLabel:
return SegmentioCellWithImageUnderLabel.self
case .ImageBeforeLabel:
case .imageBeforeLabel:
return SegmentioCellWithImageBeforeLabel.self
case .ImageAfterLabel:
case .imageAfterLabel:
return SegmentioCellWithImageAfterLabel.self
}
}
segmentioCollectionView?.registerClass(
segmentioCollectionView?.register(
cellClass,
forCellWithReuseIdentifier: segmentioStyle.rawValue
)
@ -243,13 +243,13 @@ public class Segmentio: UIView {
// MARK: Horizontal separators setup
private func setupHorizontalSeparatorIfPossible() {
fileprivate func setupHorizontalSeparatorIfPossible() {
if superview != nil && segmentioOptions.horizontalSeparatorOptions != nil {
setupHorizontalSeparator()
}
}
private func setupHorizontalSeparator() {
fileprivate func setupHorizontalSeparator() {
topSeparatorView?.removeFromSuperview()
bottomSeparatorView?.removeFromSuperview()
@ -260,16 +260,16 @@ public class Segmentio: UIView {
let height = horizontalSeparatorOptions.height
let type = horizontalSeparatorOptions.type
if type == .Top || type == .TopAndBottom {
topSeparatorView = UIView(frame: CGRectZero)
if type == .top || type == .topAndBottom {
topSeparatorView = UIView(frame: CGRect.zero)
setupConstraintsForSeparatorView(
separatorView: topSeparatorView,
originY: 0
)
}
if type == .Bottom || type == .TopAndBottom {
bottomSeparatorView = UIView(frame: CGRectZero)
if type == .bottom || type == .topAndBottom {
bottomSeparatorView = UIView(frame: CGRect.zero)
setupConstraintsForSeparatorView(
separatorView: bottomSeparatorView,
originY: frame.maxY - height
@ -277,8 +277,8 @@ public class Segmentio: UIView {
}
}
private func setupConstraintsForSeparatorView(separatorView separatorView: UIView?, originY: CGFloat) {
guard let horizontalSeparatorOptions = segmentioOptions.horizontalSeparatorOptions, separatorView = separatorView else {
fileprivate func setupConstraintsForSeparatorView(separatorView: UIView?, originY: CGFloat) {
guard let horizontalSeparatorOptions = segmentioOptions.horizontalSeparatorOptions, let separatorView = separatorView else {
return
}
@ -288,61 +288,61 @@ public class Segmentio: UIView {
let topConstraint = NSLayoutConstraint(
item: separatorView,
attribute: .Top,
relatedBy: .Equal,
attribute: .top,
relatedBy: .equal,
toItem: superview,
attribute: .Top,
attribute: .top,
multiplier: 1,
constant: originY
)
topConstraint.active = true
topConstraint.isActive = true
let leadingConstraint = NSLayoutConstraint(
item: separatorView,
attribute: .Leading,
relatedBy: .Equal,
attribute: .leading,
relatedBy: .equal,
toItem: self,
attribute: .Leading,
attribute: .leading,
multiplier: 1,
constant: 0
)
leadingConstraint.active = true
leadingConstraint.isActive = true
let trailingConstraint = NSLayoutConstraint(
item: separatorView,
attribute: .Trailing,
relatedBy: .Equal,
attribute: .trailing,
relatedBy: .equal,
toItem: self,
attribute: .Trailing,
attribute: .trailing,
multiplier: 1,
constant: 0
)
trailingConstraint.active = true
trailingConstraint.isActive = true
let heightConstraint = NSLayoutConstraint(
item: separatorView,
attribute: .Height,
relatedBy: .Equal,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .NotAnAttribute,
attribute: .notAnAttribute,
multiplier: 1,
constant: horizontalSeparatorOptions.height
)
heightConstraint.active = true
heightConstraint.isActive = true
}
// MARK: CAShapeLayers setup
private func setupShapeLayer(shapeLayer shapeLayer: CAShapeLayer, backgroundColor: UIColor, height: CGFloat, sublayer: CALayer) {
shapeLayer.fillColor = backgroundColor.CGColor
shapeLayer.strokeColor = backgroundColor.CGColor
fileprivate func setupShapeLayer(shapeLayer: CAShapeLayer, backgroundColor: UIColor, height: CGFloat, sublayer: CALayer) {
shapeLayer.fillColor = backgroundColor.cgColor
shapeLayer.strokeColor = backgroundColor.cgColor
shapeLayer.lineWidth = height
layer.insertSublayer(shapeLayer, below: sublayer)
}
// MARK: - Actions:
// MARK: Reload segmentio
private func reloadSegmentio() {
fileprivate func reloadSegmentio() {
segmentioCollectionView?.reloadData()
scrollToItemAtContext()
moveShapeLayerAtContext()
@ -350,7 +350,7 @@ public class Segmentio: UIView {
// MARK: Move shape layer to item
private func moveShapeLayerAtContext() {
fileprivate func moveShapeLayerAtContext() {
if let indicatorLayer = indicatorLayer, let options = segmentioOptions.indicatorOptions {
let item = itemInSuperview(ratio: options.ratio)
let context = contextForItem(item)
@ -390,8 +390,8 @@ public class Segmentio: UIView {
// MARK: Scroll to item
private func scrollToItemAtContext() {
guard let numberOfSections = segmentioCollectionView?.numberOfSections() else {
fileprivate func scrollToItemAtContext() {
guard let numberOfSections = segmentioCollectionView?.numberOfSections else {
return
}
@ -400,20 +400,20 @@ public class Segmentio: UIView {
if context.isLastOrPrelastVisibleCell == true {
let newIndex = selectedSegmentioIndex + (context.isLastCell ? 0 : 1)
let newIndexPath = NSIndexPath(forItem: newIndex, inSection: numberOfSections - 1)
segmentioCollectionView?.scrollToItemAtIndexPath(
newIndexPath,
atScrollPosition: .None,
let newIndexPath = IndexPath(item: newIndex, section: numberOfSections - 1)
segmentioCollectionView?.scrollToItem(
at: newIndexPath,
at: UICollectionViewScrollPosition(),
animated: true
)
}
if context.isFirstOrSecondVisibleCell == true {
let newIndex = selectedSegmentioIndex - (context.isFirstIndex ? 1 : 0)
let newIndexPath = NSIndexPath(forItem: newIndex, inSection: numberOfSections - 1)
segmentioCollectionView?.scrollToItemAtIndexPath(
newIndexPath,
atScrollPosition: .None,
let newIndexPath = IndexPath(item: newIndex, section: numberOfSections - 1)
segmentioCollectionView?.scrollToItem(
at: newIndexPath,
at: UICollectionViewScrollPosition(),
animated: true
)
}
@ -421,38 +421,38 @@ public class Segmentio: UIView {
// MARK: Move shape layer
private func moveShapeLayer(shapeLayer: CAShapeLayer, startPoint: CGPoint, endPoint: CGPoint, animated: Bool = false) {
fileprivate func moveShapeLayer(_ shapeLayer: CAShapeLayer, startPoint: CGPoint, endPoint: CGPoint, animated: Bool = false) {
var endPointWithVerticalSeparator = endPoint
let isLastItem = selectedSegmentioIndex + 1 == segmentioItems.count
endPointWithVerticalSeparator.x = endPoint.x - (isLastItem ? 0 : 1)
let shapeLayerPath = UIBezierPath()
shapeLayerPath.moveToPoint(startPoint)
shapeLayerPath.addLineToPoint(endPointWithVerticalSeparator)
shapeLayerPath.move(to: startPoint)
shapeLayerPath.addLine(to: endPointWithVerticalSeparator)
if animated == true {
isPerformingScrollAnimation = true
userInteractionEnabled = false
isUserInteractionEnabled = false
CATransaction.begin()
let animation = CABasicAnimation(keyPath: "path")
animation.fromValue = shapeLayer.path
animation.toValue = shapeLayerPath.CGPath
animation.toValue = shapeLayerPath.cgPath
animation.duration = animationDuration
CATransaction.setCompletionBlock() {
self.isPerformingScrollAnimation = false
self.userInteractionEnabled = true
self.isUserInteractionEnabled = true
}
shapeLayer.addAnimation(animation, forKey: "path")
shapeLayer.add(animation, forKey: "path")
CATransaction.commit()
}
shapeLayer.path = shapeLayerPath.CGPath
shapeLayer.path = shapeLayerPath.cgPath
}
// MARK: - Context for item
private func contextForItem(item: ItemInSuperview) -> Context {
fileprivate func contextForItem(_ item: ItemInSuperview) -> Context {
let cellFrame = item.cellFrameInSuperview
let cellWidth = cellFrame.width
let lastCellMinX = floor(item.collectionViewWidth - cellWidth)
@ -476,10 +476,10 @@ public class Segmentio: UIView {
// MARK: - Item in superview
private func itemInSuperview(ratio ratio: CGFloat = 1) -> ItemInSuperview {
fileprivate func itemInSuperview(ratio: CGFloat = 1) -> ItemInSuperview {
var collectionViewWidth: CGFloat = 0
var cellWidth: CGFloat = 0
var cellRect = CGRectZero
var cellRect = CGRect.zero
var shapeLayerWidth: CGFloat = 0
if let collectionView = segmentioCollectionView {
@ -508,7 +508,7 @@ public class Segmentio: UIView {
// MARK: - Indicator point Y
private func indicatorPointY() -> CGFloat {
fileprivate func indicatorPointY() -> CGFloat {
var indicatorPointY: CGFloat = 0
guard let indicatorOptions = segmentioOptions.indicatorOptions else {
@ -516,9 +516,9 @@ public class Segmentio: UIView {
}
switch indicatorOptions.type {
case .Top:
case .top:
indicatorPointY = (indicatorOptions.height / 2)
case .Bottom:
case .bottom:
indicatorPointY = frame.height - (indicatorOptions.height / 2)
}
@ -527,14 +527,14 @@ public class Segmentio: UIView {
}
let separatorHeight = horizontalSeparatorOptions.height
let isIndicatorTop = indicatorOptions.type == .Top
let isIndicatorTop = indicatorOptions.type == .top
switch horizontalSeparatorOptions.type {
case .Top:
case .top:
indicatorPointY = isIndicatorTop ? indicatorPointY + separatorHeight : indicatorPointY
case .Bottom:
case .bottom:
indicatorPointY = isIndicatorTop ? indicatorPointY : indicatorPointY - separatorHeight
case .TopAndBottom:
case .topAndBottom:
indicatorPointY = isIndicatorTop ? indicatorPointY + separatorHeight : indicatorPointY - separatorHeight
}
@ -546,14 +546,14 @@ public class Segmentio: UIView {
extension Segmentio: UICollectionViewDataSource {
public func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return segmentioItems.count ?? 0
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return segmentioItems.count
}
public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(
segmentioStyle.rawValue,
forIndexPath: indexPath) as! SegmentioCell
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: segmentioStyle.rawValue,
for: indexPath) as! SegmentioCell
cell.configure(
content: segmentioItems[indexPath.row],
@ -573,11 +573,11 @@ extension Segmentio: UICollectionViewDataSource {
extension Segmentio: UICollectionViewDelegate {
public func collectionView(collectionView: UICollectionView, shouldSelectItemAtIndexPath indexPath: NSIndexPath) -> Bool {
public func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
return true
}
public func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
selectedSegmentioIndex = indexPath.row
}
@ -587,12 +587,9 @@ extension Segmentio: UICollectionViewDelegate {
extension Segmentio: UICollectionViewDelegateFlowLayout {
public func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let maxVisibleItems = segmentioOptions.maxVisibleItems > segmentioItems.count ? CGFloat(segmentioItems.count) : CGFloat(segmentioOptions.maxVisibleItems)
return CGSize(
width: floor(collectionView.frame.width / maxVisibleItems),
height: collectionView.frame.height
)
return CGSize( width: floor(collectionView.frame.width / maxVisibleItems), height: collectionView.frame.height)
}
}
@ -601,17 +598,17 @@ extension Segmentio: UICollectionViewDelegateFlowLayout {
extension Segmentio: UIScrollViewDelegate {
public func scrollViewDidScroll(scrollView: UIScrollView) {
if isPerformingScrollAnimation == true {
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
if isPerformingScrollAnimation {
return
}
if let options = segmentioOptions.indicatorOptions, indicatorLayer = indicatorLayer {
if let options = segmentioOptions.indicatorOptions, let indicatorLayer = indicatorLayer {
let item = itemInSuperview(ratio: options.ratio)
moveShapeLayer(
indicatorLayer,
startPoint: CGPointMake(item.startX, indicatorPointY()),
endPoint: CGPointMake(item.endX, indicatorPointY()),
startPoint: CGPoint(x: item.startX, y: indicatorPointY()),
endPoint: CGPoint(x: item.endX, y: indicatorPointY()),
animated: false
)
}
@ -667,4 +664,4 @@ extension Segmentio.Points {
endPoint = CGPoint(x: endX, y: pointY)
}
}
}

View File

@ -11,6 +11,7 @@ import UIKit
// MARK: - Item
public struct SegmentioItem {
var title: String?
var image: UIImage?
var badgeCount: Int?
@ -21,7 +22,7 @@ public struct SegmentioItem {
self.image = image
}
public mutating func setupBadgeWithCount(count: Int, color: UIColor = .redColor()) {
public mutating func addBadge(_ count: Int, color: UIColor) {
self.badgeCount = count
self.badgeColor = color
}
@ -36,14 +37,15 @@ public struct SegmentioItem {
// MARK: - Content view
public struct SegmentioState {
var backgroundColor: UIColor
var titleFont: UIFont
var titleTextColor: UIColor
public init(
backgroundColor: UIColor = UIColor.clearColor(),
titleFont: UIFont = UIFont.systemFontOfSize(UIFont.smallSystemFontSize()),
titleTextColor: UIColor = UIColor.blackColor()) {
backgroundColor: UIColor = .clear,
titleFont: UIFont = UIFont.systemFont(ofSize: UIFont.smallSystemFontSize),
titleTextColor: UIColor = .black) {
self.backgroundColor = backgroundColor
self.titleFont = titleFont
self.titleTextColor = titleTextColor
@ -54,18 +56,20 @@ public struct SegmentioState {
// MARK: - Horizontal separator
public enum SegmentioHorizontalSeparatorType {
case Top, Bottom, TopAndBottom
case top
case bottom
case topAndBottom
}
public struct SegmentioHorizontalSeparatorOptions {
var type: SegmentioHorizontalSeparatorType
var height: CGFloat
var color: UIColor
public init(
type: SegmentioHorizontalSeparatorType = .TopAndBottom,
height: CGFloat = 1.0,
color: UIColor = UIColor.darkGrayColor()) {
public init(type: SegmentioHorizontalSeparatorType = .topAndBottom, height: CGFloat = 1.0, color: UIColor = .darkGray) {
self.type = type
self.height = height
self.color = color
@ -76,10 +80,11 @@ public struct SegmentioHorizontalSeparatorOptions {
// MARK: - Vertical separator
public struct SegmentioVerticalSeparatorOptions {
var ratio: CGFloat
var color: UIColor
public init(ratio: CGFloat = 1.0, color: UIColor = UIColor.darkGrayColor()) {
public init(ratio: CGFloat = 1.0, color: UIColor = .darkGray) {
self.ratio = ratio
self.color = color
}
@ -89,20 +94,20 @@ public struct SegmentioVerticalSeparatorOptions {
// MARK: - Indicator
public enum SegmentioIndicatorType {
case Top, Bottom
case top
case bottom
}
public struct SegmentioIndicatorOptions {
var type: SegmentioIndicatorType
var ratio: CGFloat
var height: CGFloat
var color: UIColor
public init(
type: SegmentioIndicatorType = .Bottom,
ratio: CGFloat = 1.0,
height: CGFloat = 2.0,
color: UIColor = UIColor.orangeColor()) {
public init(type: SegmentioIndicatorType = .bottom, ratio: CGFloat = 1.0, height: CGFloat = 2.0, color: UIColor = .orange) {
self.type = type
self.ratio = ratio
self.height = height
@ -114,20 +119,21 @@ public struct SegmentioIndicatorOptions {
// MARK: - Control options
public enum SegmentioStyle: String {
case OnlyLabel, OnlyImage, ImageOverLabel, ImageUnderLabel, ImageBeforeLabel, ImageAfterLabel
case onlyLabel, onlyImage, imageOverLabel, imageUnderLabel, imageBeforeLabel, imageAfterLabel
public static let allStyles = [
OnlyLabel,
OnlyImage,
ImageOverLabel,
ImageUnderLabel,
ImageBeforeLabel,
ImageAfterLabel
onlyLabel,
onlyImage,
imageOverLabel,
imageUnderLabel,
imageBeforeLabel,
imageAfterLabel
]
public func isWithText() -> Bool {
switch self {
case .OnlyLabel, .ImageOverLabel, .ImageUnderLabel, .ImageBeforeLabel, .ImageAfterLabel:
case .onlyLabel, .imageOverLabel, .imageUnderLabel, .imageBeforeLabel, .imageAfterLabel:
return true
default:
return false
@ -136,7 +142,7 @@ public enum SegmentioStyle: String {
public func isWithImage() -> Bool {
switch self {
case .ImageOverLabel, .ImageUnderLabel, .ImageBeforeLabel, .ImageAfterLabel, .OnlyImage:
case .imageOverLabel, .imageUnderLabel, .imageBeforeLabel, .imageAfterLabel, .onlyImage:
return true
default:
return false
@ -147,6 +153,7 @@ public enum SegmentioStyle: String {
public typealias SegmentioStates = (defaultState: SegmentioState, selectedState: SegmentioState, highlightedState: SegmentioState)
public struct SegmentioOptions {
var backgroundColor: UIColor
var maxVisibleItems: Int
var scrollEnabled: Bool
@ -158,7 +165,7 @@ public struct SegmentioOptions {
var states: SegmentioStates
public init() {
self.backgroundColor = UIColor.lightGrayColor()
self.backgroundColor = .lightGray
self.maxVisibleItems = 4
self.scrollEnabled = true
@ -167,8 +174,8 @@ public struct SegmentioOptions {
self.indicatorOptions = SegmentioIndicatorOptions()
self.imageContentMode = .Center
self.labelTextAlignment = .Center
self.imageContentMode = .center
self.labelTextAlignment = .center
self.states = SegmentioStates(
defaultState: SegmentioState(),
@ -189,4 +196,4 @@ public struct SegmentioOptions {
self.states = segmentStates
}
}
}