Update due to swift 3 guidelines

This commit is contained in:
Serhii Butenko 2016-10-10 08:13:24 +03:00
parent 92cbd32517
commit 5dae83d735
23 changed files with 297 additions and 308 deletions

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

@ -399,14 +399,6 @@
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0700;
TargetAttributes = {
1773C65AAC9F8837BB8142660D7320E0 = {
LastSwiftMigration = 0800;
};
D69CC732EFB91EE42BE73E5030BD387C = {
LastSwiftMigration = 0800;
};
};
};
buildConfigurationList = 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */;
compatibilityVersion = "Xcode 3.2";
@ -504,7 +496,7 @@
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
47BEF9D903506B003EA5C2B249729489 /* Debug */ = {
015A368F878AC3E2CEAE21DDE8026304 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
@ -522,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;
@ -541,100 +534,13 @@
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 */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 37602088D7DDBEBF54BCE7CAF18CB105 /* Pods-Segmentio_Example.debug.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
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";
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";
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;
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 */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 808E8A2F66FEF9BFA423C8B51FEB3FD3 /* Pods-Segmentio_Example.release.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
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";
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";
MTL_ENABLE_DEBUG_INFO = NO;
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_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
name = Release;
};
A6D8F8AC9425BACBC3621CFD7597790C /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = AAF3441A43AA58E58A7340FA1E66271B /* Segmentio.xcconfig */;
buildSettings = {
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Segmentio";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
INFOPLIST_FILE = "Target Support Files/Segmentio/ResourceBundle-Segmentio-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_NAME = Segmentio;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = bundle;
};
name = Debug;
};
AAF678CED40D3499169D10F63CA0719E /* Release */ = {
44CDBB6D11DE06DB64D6268622BDC47E /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
@ -652,6 +558,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 = YES;
ENABLE_NS_ASSERTIONS = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
@ -666,34 +573,20 @@
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;
};
B39C8A659F54F5D7007A70CE400454EA /* Release */ = {
6939D89BCF3CB71D8A0CB554AEAC1779 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = AAF3441A43AA58E58A7340FA1E66271B /* Segmentio.xcconfig */;
buildSettings = {
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Segmentio";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
INFOPLIST_FILE = "Target Support Files/Segmentio/ResourceBundle-Segmentio-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_NAME = Segmentio;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = bundle;
};
name = Release;
};
B54261FEDDC960542CA187AA5E14BC7D /* Debug */ = {
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;
DEFINES_MODULE = YES;
@ -720,11 +613,118 @@
};
name = Debug;
};
F03A1D5CC9DD916A3B05610779B9C8F0 /* Release */ = {
69F41B3AE04E5DCE90065CD8E029712C /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 808E8A2F66FEF9BFA423C8B51FEB3FD3 /* Pods-Segmentio_Example.release.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-with-dsym";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
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";
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";
MTL_ENABLE_DEBUG_INFO = NO;
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;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
name = Release;
};
A6D8F8AC9425BACBC3621CFD7597790C /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = AAF3441A43AA58E58A7340FA1E66271B /* Segmentio.xcconfig */;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Segmentio";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
INFOPLIST_FILE = "Target Support Files/Segmentio/ResourceBundle-Segmentio-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_NAME = Segmentio;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = bundle;
};
name = Debug;
};
B39C8A659F54F5D7007A70CE400454EA /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = AAF3441A43AA58E58A7340FA1E66271B /* Segmentio.xcconfig */;
buildSettings = {
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Segmentio";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
INFOPLIST_FILE = "Target Support Files/Segmentio/ResourceBundle-Segmentio-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_NAME = Segmentio;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = bundle;
};
name = Release;
};
BF58FEE71132386297AFD4D409190547 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 37602088D7DDBEBF54BCE7CAF18CB105 /* Pods-Segmentio_Example.debug.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;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
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";
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";
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;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
name = Debug;
};
E8435E0DCC8F7A80386C452616DACB34 /* Release */ = {
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-with-dsym";
DEFINES_MODULE = YES;
@ -756,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;
@ -765,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;
@ -783,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

@ -322,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 */
@ -389,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;
@ -427,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;

View File

@ -18,7 +18,6 @@ extension String {
options: .regularExpression,
range: nil
)
string.replaceSubrange(startIndex...startIndex, with: String(self[startIndex]))
return String(string.characters.prefix(1)).capitalized + String(string.lowercased().characters.dropFirst())

View File

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

View File

@ -11,14 +11,14 @@ import UIKit
class AppearanceConfigurator {
class func configureNavigationBar() {
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
UIApplication.shared.statusBarStyle = .lightContent
UINavigationBar.appearance().barTintColor = ColorPalette.WhiteColor
UINavigationBar.appearance().barTintColor = ColorPalette.white
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().tintColor = ColorPalette.BlackColor
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

@ -66,7 +66,7 @@ extension ContentViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! ExampleTableViewCell
cell.hintLabel?.text = hints?[(indexPath as NSIndexPath).row]
cell.hintLabel?.text = hints?[indexPath.row]
return cell
}

View File

@ -13,7 +13,7 @@ private let animateDuration: TimeInterval = 0.6
class EmbedContainerViewController: UIViewController {
var style = SegmentioStyle.OnlyImage
var style = SegmentioStyle.onlyImage
fileprivate var currentViewController: UIViewController?

View File

@ -11,7 +11,7 @@ import Segmentio
class ExampleViewController: UIViewController {
var segmentioStyle = SegmentioStyle.ImageOverLabel
var segmentioStyle = SegmentioStyle.imageOverLabel
@IBOutlet fileprivate weak var segmentViewHeightConstraint: NSLayoutConstraint!
@IBOutlet fileprivate weak var segmentioView: Segmentio!
@ -35,9 +35,9 @@ 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
@ -63,20 +63,13 @@ 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)
}
}
}
fileprivate func setupBadgeCountForIndex(_ index: Int) {
segmentioView.setupBadgeAtIndex(
index,
count: 10,
color: ColorPalette.CoralColor
)
segmentioView.addBadge(at: index, count: 10, color: ColorPalette.coral)
}
fileprivate func segmentioContent() -> [SegmentioItem] {
@ -93,14 +86,14 @@ class ExampleViewController: UIViewController {
fileprivate func segmentioOptions() -> SegmentioOptions {
var imageContentMode = UIViewContentMode.center
switch segmentioStyle {
case .ImageBeforeLabel, .ImageAfterLabel:
case .imageBeforeLabel, .imageAfterLabel:
imageContentMode = .scaleAspectFit
default:
break
}
return SegmentioOptions(
backgroundColor: ColorPalette.WhiteColor,
backgroundColor: ColorPalette.white,
maxVisibleItems: 3,
scrollEnabled: true,
indicatorOptions: segmentioIndicatorOptions(),
@ -113,22 +106,22 @@ class ExampleViewController: UIViewController {
}
fileprivate func segmentioStates() -> SegmentioStates {
let font = UIFont.exampleAvenirMediumWithSize(13)
let font = UIFont.exampleAvenirMedium(ofSize: 13)
return SegmentioStates(
defaultState: segmentioState(
backgroundColor: UIColor.clear,
backgroundColor: .clear,
titleFont: font,
titleTextColor: ColorPalette.GrayChateauColor
titleTextColor: ColorPalette.grayChateau
),
selectedState: segmentioState(
backgroundColor: UIColor.clear,
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
)
)
}
@ -138,49 +131,37 @@ class ExampleViewController: UIViewController {
}
fileprivate func segmentioIndicatorOptions() -> SegmentioIndicatorOptions {
return SegmentioIndicatorOptions(
type: .bottom,
ratio: 1,
height: 5,
color: ColorPalette.CoralColor
)
return SegmentioIndicatorOptions(type: .bottom, ratio: 1, height: 5, color: ColorPalette.coral)
}
fileprivate func segmentioHorizontalSeparatorOptions() -> SegmentioHorizontalSeparatorOptions {
return SegmentioHorizontalSeparatorOptions(
type: .topAndBottom,
height: 1,
color: ColorPalette.WhiteSmokeColor
)
return SegmentioHorizontalSeparatorOptions(type: .topAndBottom, height: 1, color: ColorPalette.whiteSmoke)
}
fileprivate func segmentioVerticalSeparatorOptions() -> SegmentioVerticalSeparatorOptions {
return SegmentioVerticalSeparatorOptions(
ratio: 1,
color: ColorPalette.WhiteSmokeColor
)
return SegmentioVerticalSeparatorOptions(ratio: 1, color: ColorPalette.whiteSmoke)
}
// Example viewControllers
fileprivate func preparedViewControllers() -> [ContentViewController] {
let tornadoController = ContentViewController.create()
tornadoController.disaster = Disaster(cardName: "Before tornado", hints: Hints.Tornado)
tornadoController.disaster = Disaster(cardName: "Before tornado", hints: Hints.tornado)
let earthquakesController = ContentViewController.create()
earthquakesController.disaster = Disaster(cardName: "Before earthquakes", hints: Hints.Earthquakes)
earthquakesController.disaster = Disaster(cardName: "Before earthquakes", hints: Hints.earthquakes)
let extremeHeatController = ContentViewController.create()
extremeHeatController.disaster = Disaster(cardName: "Before extreme heat", hints: Hints.ExtremeHeat)
extremeHeatController.disaster = Disaster(cardName: "Before extreme heat", hints: Hints.extremeHeat)
let eruptionController = ContentViewController.create()
eruptionController.disaster = Disaster(cardName: "Before eruption", hints: Hints.Eruption)
eruptionController.disaster = Disaster(cardName: "Before eruption", hints: Hints.eruption)
let floodsController = ContentViewController.create()
floodsController.disaster = Disaster(cardName: "Before floods", hints: Hints.Floods)
floodsController.disaster = Disaster(cardName: "Before floods", hints: Hints.floods)
let wildfiresController = ContentViewController.create()
wildfiresController.disaster = Disaster(cardName: "Before wildfires", hints: Hints.Wildfires)
wildfiresController.disaster = Disaster(cardName: "Before wildfires", hints: Hints.wildfires)
return [
tornadoController,
@ -195,7 +176,6 @@ class ExampleViewController: UIViewController {
fileprivate func selectedSegmentioIndex() -> Int {
return 0
}
// MARK: - Setup container view
@ -213,7 +193,7 @@ class ExampleViewController: UIViewController {
height: scrollView.frame.height
)
addChildViewController(viewController)
scrollView.addSubview(viewController.view, options: .UseAutoresize) // module's extension
scrollView.addSubview(viewController.view, options: .useAutoresize) // module's extension
viewController.didMove(toParentViewController: self)
}
}
@ -223,7 +203,7 @@ class ExampleViewController: UIViewController {
fileprivate func goToControllerAtIndex(_ index: Int) {
segmentioView.selectedSegmentioIndex = index
}
}
extension ExampleViewController: UIScrollViewDelegate {

View File

@ -11,7 +11,7 @@ import Segmentio
class HomeViewController: UIViewController {
fileprivate var currentStyle = SegmentioStyle.OnlyImage
fileprivate var currentStyle = SegmentioStyle.onlyImage
fileprivate var containerViewController: EmbedContainerViewController?
// MARK: - Lifecycle

View File

@ -24,12 +24,13 @@ class SideMenuViewController: UIViewController {
@IBOutlet fileprivate weak var menuTableViewWidthConstraint: NSLayoutConstraint!
fileprivate var menuItems = SegmentioStyle.allStyles
fileprivate var currentStyle = SegmentioStyle.OnlyImage
fileprivate var currentStyle = SegmentioStyle.onlyImage
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
menuTableView.isHidden = true
view.isHidden = true
menuTableViewWidthConstraint.constant = UIScreen.main.bounds.width * 0.7
@ -46,8 +47,9 @@ class SideMenuViewController: UIViewController {
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.present(self, animated: false) { [weak self] in
self?.view.isHidden = false
self?.menuTableView.frame.origin = CGPoint(x: -size.width, y: 0)
@ -55,7 +57,7 @@ class SideMenuViewController: UIViewController {
withDuration: animationDuration,
animations: {
self?.view.backgroundColor = UIColor.black.withAlphaComponent(0.63)
self?.slideAnimationToPoint(CGPoint.zero)
self?.slideAnimationToPoint(.zero)
self?.menuTableView.isHidden = false
}
)
@ -65,37 +67,31 @@ class SideMenuViewController: UIViewController {
// MARK: - Private functions
fileprivate func setupGestureRecognizers() {
let dissmisSideMenuSelector = #selector(SideMenuViewController.dissmisSideMenu)
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
)
let swipeRecognizer = UISwipeGestureRecognizer(target: self, action: dissmisSideMenuSelector)
swipeRecognizer.direction = .left
swipeRecognizer.delegate = self
view.addGestureRecognizer(swipeRecognizer)
}
fileprivate func didSelectItemAtIndexPath(_ indexPath: IndexPath) {
currentStyle = SegmentioStyle.allStyles[(indexPath as NSIndexPath).row]
dissmisSideMenu()
fileprivate func didSelectItem(at indexPath: IndexPath) {
currentStyle = SegmentioStyle.allStyles[indexPath.row]
dismissSideMenu()
}
@objc fileprivate func dissmisSideMenu() {
@objc fileprivate func dismissSideMenu() {
let size = view.frame.size
UIView.animate(
withDuration: animationDuration,
animations: {
self.slideAnimationToPoint(CGPoint(x: -size.width, y: 0))
self.view.backgroundColor = UIColor.clear
self.view.backgroundColor = .clear
},
completion: { _ in
self.view.isHidden = true
@ -106,9 +102,9 @@ class SideMenuViewController: UIViewController {
}
fileprivate func slideAnimationToPoint(_ point: CGPoint) {
UIView.animate(withDuration: animationDuration, animations: {
UIView.animate(withDuration: animationDuration) {
self.menuTableView.frame.origin = point
})
}
}
fileprivate func uncheckCurrentStyle() {
@ -116,10 +112,7 @@ class SideMenuViewController: UIViewController {
return
}
let activeIndexPath = IndexPath(
row: currentStyleIndex,
section: menuTableView.numberOfSections - 1
)
let activeIndexPath = IndexPath(row: currentStyleIndex, section: menuTableView.numberOfSections - 1)
let activeCell = menuTableView.cellForRow(at: activeIndexPath)
activeCell?.imageView?.image = defaultCheckboxImage
@ -130,19 +123,17 @@ class SideMenuViewController: UIViewController {
extension SideMenuViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return menuItems.count ?? 0
return menuItems.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let reuseIdentifier = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier)
let isCurrentStyle = currentStyle == menuItems[(indexPath as NSIndexPath).row]
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
let isCurrentStyle = currentStyle == menuItems[indexPath.row]
cell!.textLabel?.text = menuItems[(indexPath as NSIndexPath).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
}
}
@ -152,11 +143,11 @@ extension SideMenuViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
if currentStyle != menuItems[(indexPath as NSIndexPath).row] {
if currentStyle != menuItems[indexPath.row] {
uncheckCurrentStyle()
cell?.imageView?.image = selectedCheckboxImage
}
didSelectItemAtIndexPath(indexPath)
didSelectItem(at: indexPath)
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
@ -166,6 +157,7 @@ extension SideMenuViewController: UITableViewDelegate {
}
extension SideMenuViewController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}

View File

@ -10,12 +10,7 @@ import UIKit
class BadgeViewPresenter {
func addBadgeForContainerView(
_ containerView: UIView,
counterValue: Int,
backgroundColor: UIColor = .red,
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,11 +20,7 @@ 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.bringSubview(toFront: badgeView)
@ -77,15 +68,25 @@ class BadgeViewPresenter {
}
enum Separator {
case top
case bottom
case topAndBottom
}
// MARK: Badges views creation
extension BadgeViewPresenter {
fileprivate 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,9 +5,11 @@ private let BadgeCounterOverMaxValueText = "99+"
private let standardSizedNibName = "BadgeWithCounterViewStandardSized"
private let bigSizedNibName = "BadgeWithCounterViewBigSized"
enum CounterBadgeSize {
enum BadgeSize {
case standard
case big
}
class BadgeWithCounterView: UIView {
@ -15,14 +17,14 @@ class BadgeWithCounterView: UIView {
@IBOutlet fileprivate weak var counterValueLabel: UILabel!
@IBOutlet fileprivate weak var backgroundImageView: UIImageView!
class func instanceFromNib(size: CounterBadgeSize) -> BadgeWithCounterView {
class func instanceFromNib(size: BadgeSize) -> BadgeWithCounterView {
let nibName = nibNameForSize(size)
let podBundle = Bundle(for: self.classForCoder())
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: CGRect.zero)
return BadgeWithCounterView(frame: .zero)
}
func setBadgeCounterValue(_ counterValue: Int) {
@ -39,8 +41,7 @@ class BadgeWithCounterView: UIView {
backgroundImageView.backgroundColor = color
}
fileprivate 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

@ -24,7 +24,7 @@ class SegmentioCell: UICollectionViewCell {
var cellSelected = false
fileprivate var options = SegmentioOptions()
fileprivate var style = SegmentioStyle.ImageOverLabel
fileprivate var style = SegmentioStyle.imageOverLabel
fileprivate let verticalSeparatorLayer = CAShapeLayer()
fileprivate let badgePresenter = BadgeViewPresenter()
@ -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:
@ -147,7 +147,7 @@ class SegmentioCell: UICollectionViewCell {
return
}
if style == .OnlyImage {
if style == .onlyImage {
badgePresenter.addBadgeForContainerView(
imageContainerView!,
counterValue: badgeCount,

View File

@ -11,18 +11,24 @@ import UIKit
private typealias SubviewTreeModifier = ((Void) -> UIView)
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 {
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])
@ -49,7 +55,7 @@ extension UIView {
}
}
fileprivate func dictionaryOfNames(_ views:[UIView]) -> [String: UIView] {
fileprivate func dictionaryOfNames(_ views: [UIView]) -> [String: UIView] {
var container = [String: UIView]()
for (_, value) in views.enumerated() {
container["subview"] = value

View File

@ -49,7 +49,7 @@ open class Segmentio: UIView {
fileprivate var segmentioCollectionView: UICollectionView?
fileprivate var segmentioItems = [SegmentioItem]()
fileprivate var segmentioOptions = SegmentioOptions()
fileprivate var segmentioStyle = SegmentioStyle.ImageOverLabel
fileprivate var segmentioStyle = SegmentioStyle.imageOverLabel
fileprivate var isPerformingScrollAnimation = false
fileprivate var topSeparatorView: UIView?
@ -110,12 +110,12 @@ open class Segmentio: UIView {
collectionView.showsVerticalScrollIndicator = false
collectionView.bounces = true
collectionView.isScrollEnabled = segmentioOptions.scrollEnabled
collectionView.backgroundColor = UIColor.clear
collectionView.backgroundColor = .clear
segmentioCollectionView = collectionView
if let segmentioCollectionView = segmentioCollectionView {
addSubview(segmentioCollectionView, options: .Overlay)
addSubview(segmentioCollectionView, options: .overlay)
}
}
@ -168,7 +168,7 @@ open class Segmentio: UIView {
backgroundColor = options.backgroundColor
}
if segmentioOptions.states.selectedState.backgroundColor != UIColor.clear {
if segmentioOptions.states.selectedState.backgroundColor != .clear {
selectedLayer = CAShapeLayer()
if let selectedLayer = selectedLayer, let sublayer = segmentioCollectionView?.layer {
setupShapeLayer(
@ -203,12 +203,12 @@ open class Segmentio: UIView {
setupHorizontalSeparatorIfPossible()
}
open 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()
}
open func removeBadgeAtIndex(_ index: Int) {
open func removeBadge(at index: Int) {
segmentioItems[index].removeBadge()
segmentioCollectionView?.reloadData()
}
@ -218,17 +218,17 @@ open class Segmentio: UIView {
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
}
}
@ -547,7 +547,7 @@ open class Segmentio: UIView {
extension Segmentio: UICollectionViewDataSource {
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return segmentioItems.count ?? 0
return segmentioItems.count
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
@ -556,13 +556,13 @@ extension Segmentio: UICollectionViewDataSource {
for: indexPath) as! SegmentioCell
cell.configure(
content: segmentioItems[(indexPath as NSIndexPath).row],
content: segmentioItems[indexPath.row],
style: segmentioStyle,
options: segmentioOptions,
isLastCell: (indexPath as NSIndexPath).row == segmentioItems.count - 1
isLastCell: indexPath.row == segmentioItems.count - 1
)
cell.configure(selected: ((indexPath as NSIndexPath).row == selectedSegmentioIndex))
cell.configure(selected: (indexPath.row == selectedSegmentioIndex))
return cell
}
@ -578,7 +578,7 @@ extension Segmentio: UICollectionViewDelegate {
}
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
selectedSegmentioIndex = (indexPath as NSIndexPath).row
selectedSegmentioIndex = indexPath.row
}
}
@ -589,10 +589,7 @@ extension Segmentio: UICollectionViewDelegateFlowLayout {
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)
}
}
@ -602,7 +599,7 @@ extension Segmentio: UICollectionViewDelegateFlowLayout {
extension Segmentio: UIScrollViewDelegate {
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
if isPerformingScrollAnimation == true {
if isPerformingScrollAnimation {
return
}

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 = .red) {
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.clear,
backgroundColor: UIColor = .clear,
titleFont: UIFont = UIFont.systemFont(ofSize: UIFont.smallSystemFontSize),
titleTextColor: UIColor = UIColor.black) {
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.darkGray) {
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.darkGray) {
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.orange) {
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.lightGray
self.backgroundColor = .lightGray
self.maxVisibleItems = 4
self.scrollEnabled = true