diff --git a/Demo.xcodeproj/project.pbxproj b/Demo.xcodeproj/project.pbxproj index 64cc390d..f6d73260 100644 --- a/Demo.xcodeproj/project.pbxproj +++ b/Demo.xcodeproj/project.pbxproj @@ -150,6 +150,8 @@ 649DE2B414E765BA54759ECE /* Pods_CocoaPods_Payment.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4AA0E4E14E48A69AC562E605 /* Pods_CocoaPods_Payment.framework */; }; 72DEC9A3753978AEF3383E56 /* Pods_CocoaPods_iPhone_Storyboard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A8F9A5FF448CDE99A084DAF4 /* Pods_CocoaPods_iPhone_Storyboard.framework */; }; 7878EFBDBA2F722E24CF62C4 /* Pods_CocoaPods_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADF7319532C286F8BEAEFF49 /* Pods_CocoaPods_Tests.framework */; }; + 7A41ADEF1DABE0EB0063DB62 /* FORMSegmentFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A41ADEE1DABE0EB0063DB62 /* FORMSegmentFieldCell.m */; }; + 7A41ADF11DAC2FCD0063DB62 /* segment-field.json in Resources */ = {isa = PBXBuildFile; fileRef = 7A41ADF01DAC2FCD0063DB62 /* segment-field.json */; }; 7A4ABAF31D7DBE7200DAE893 /* FORMSpacerFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A4ABAF21D7DBE7200DAE893 /* FORMSpacerFieldCell.m */; }; 825F6E98164CA04CDE12F270 /* Pods_CocoaPods_ModalForm.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39C9B4BD521E20A90A708235 /* Pods_CocoaPods_ModalForm.framework */; }; 82B59BA34A26252CFF5C11CB /* Pods_CocoaPods_Basic_ObjC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3FF9D9A1384FFF4964BDEA19 /* Pods_CocoaPods_Basic_ObjC.framework */; }; @@ -386,6 +388,9 @@ 50D77918C798DC1313D4D76D /* Pods-CocoaPods-iPhone-Storyboard.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CocoaPods-iPhone-Storyboard.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CocoaPods-iPhone-Storyboard/Pods-CocoaPods-iPhone-Storyboard.debug.xcconfig"; sourceTree = ""; }; 728B7C5A71C3BD93D42F469A /* Pods_CocoaPods_LoginDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CocoaPods_LoginDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7313DABFEEF45FCCCD39281E /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 7A41ADED1DABE0EB0063DB62 /* FORMSegmentFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FORMSegmentFieldCell.h; path = Switch/FORMSegmentFieldCell.h; sourceTree = ""; }; + 7A41ADEE1DABE0EB0063DB62 /* FORMSegmentFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FORMSegmentFieldCell.m; path = Switch/FORMSegmentFieldCell.m; sourceTree = ""; }; + 7A41ADF01DAC2FCD0063DB62 /* segment-field.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "segment-field.json"; sourceTree = ""; }; 7A4ABAF11D7DBE7200DAE893 /* FORMSpacerFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FORMSpacerFieldCell.h; sourceTree = ""; }; 7A4ABAF21D7DBE7200DAE893 /* FORMSpacerFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FORMSpacerFieldCell.m; sourceTree = ""; }; 7A979DD3111677D9FF793855 /* Pods_CocoaPods_Basic_Swift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CocoaPods_Basic_Swift.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -573,6 +578,7 @@ 140803641BEA50AB0098C288 /* Cells */ = { isa = PBXGroup; children = ( + 7A41ADE91DABD2930063DB62 /* Segment */, 7AB346BD1D78C83100AAAD2E /* Spacer */, 140803651BEA50AB0098C288 /* Base */, 140803681BEA50AB0098C288 /* Button */, @@ -762,6 +768,7 @@ 140804271BEA50C00098C288 /* number-formula.json */, 140804281BEA50C00098C288 /* postal_codes.json */, 140804291BEA50C00098C288 /* section-field-position.json */, + 7A41ADF01DAC2FCD0063DB62 /* segment-field.json */, 1408042A1BEA50C00098C288 /* simple-number-field.json */, 1408042B1BEA50C00098C288 /* simple-section.json */, 1408042C1BEA50C00098C288 /* simple-text-field.json */, @@ -993,6 +1000,15 @@ name = Frameworks; sourceTree = ""; }; + 7A41ADE91DABD2930063DB62 /* Segment */ = { + isa = PBXGroup; + children = ( + 7A41ADED1DABE0EB0063DB62 /* FORMSegmentFieldCell.h */, + 7A41ADEE1DABE0EB0063DB62 /* FORMSegmentFieldCell.m */, + ); + name = Segment; + sourceTree = ""; + }; 7AB346BD1D78C83100AAAD2E /* Spacer */ = { isa = PBXGroup; children = ( @@ -1196,7 +1212,7 @@ attributes = { CLASSPREFIX = ""; LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = ""; TargetAttributes = { 1406BB791BEA520D00131623 = { @@ -1337,6 +1353,7 @@ 140804491BEA50C00098C288 /* number-formula.json in Resources */, 140804441BEA50C00098C288 /* dynamic.json in Resources */, 1408043F1BEA50C00098C288 /* collapsed-groups.json in Resources */, + 7A41ADF11DAC2FCD0063DB62 /* segment-field.json in Resources */, 1408044E1BEA50C00098C288 /* simple-text-field.json in Resources */, 1408044A1BEA50C00098C288 /* postal_codes.json in Resources */, 1408044C1BEA50C00098C288 /* simple-number-field.json in Resources */, @@ -1847,6 +1864,7 @@ 140803E31BEA50AB0098C288 /* FORMFloatFormatter.m in Sources */, 1408042F1BEA50C00098C288 /* FORMDataTests.m in Sources */, 140803EB1BEA50AB0098C288 /* FORMGroupHeaderView.m in Sources */, + 7A41ADEF1DABE0EB0063DB62 /* FORMSegmentFieldCell.m in Sources */, 140804061BEA50AB0098C288 /* FORMSocialSecurityNumberValidator.m in Sources */, 7A4ABAF31D7DBE7200DAE893 /* FORMSpacerFieldCell.m in Sources */, 140803D51BEA50AB0098C288 /* FORMBaseFieldCell.m in Sources */, @@ -1968,9 +1986,9 @@ isa = XCBuildConfiguration; baseConfigurationReference = 931C1A26BDC7EECC928CEBC6 /* Pods-CocoaPods-Basic-ObjC.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEBUG_INFORMATION_FORMAT = dwarf; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = "Basic-ObjC/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; @@ -1985,9 +2003,9 @@ isa = XCBuildConfiguration; baseConfigurationReference = ED07FBCAC9A7D5BE4C66B1D9 /* Pods-CocoaPods-Basic-ObjC.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = "Basic-ObjC/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; @@ -2002,9 +2020,9 @@ isa = XCBuildConfiguration; baseConfigurationReference = F3F7C1F7C661094C0BA21EBB /* Pods-CocoaPods-Basic-Swift.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEBUG_INFORMATION_FORMAT = dwarf; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = "Basic-Swift/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; @@ -2020,9 +2038,9 @@ isa = XCBuildConfiguration; baseConfigurationReference = 2654965B789DC24EDB3A5102 /* Pods-CocoaPods-Basic-Swift.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = "Basic-Swift/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; @@ -2037,9 +2055,9 @@ isa = XCBuildConfiguration; baseConfigurationReference = F5D6B2969A264B95E1E097A4 /* Pods-CocoaPods-CustomField.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEBUG_INFORMATION_FORMAT = dwarf; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = CustomField/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.1; @@ -2055,9 +2073,9 @@ isa = XCBuildConfiguration; baseConfigurationReference = 819E8FEB0A9EFC41EB1342E9 /* Pods-CocoaPods-CustomField.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = CustomField/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.1; @@ -2072,10 +2090,10 @@ isa = XCBuildConfiguration; baseConfigurationReference = 9BF713C0A701F3557834B67F /* Pods-CocoaPods-Payment.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; DEBUG_INFORMATION_FORMAT = dwarf; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = Payment/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.1; @@ -2092,10 +2110,10 @@ isa = XCBuildConfiguration; baseConfigurationReference = 2C923DFB637E3B2E6D7C4600 /* Pods-CocoaPods-Payment.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = Payment/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.1; @@ -2111,9 +2129,9 @@ isa = XCBuildConfiguration; baseConfigurationReference = 50D77918C798DC1313D4D76D /* Pods-CocoaPods-iPhone-Storyboard.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEBUG_INFORMATION_FORMAT = dwarf; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = "iPhone-Storyboard/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; @@ -2128,9 +2146,9 @@ isa = XCBuildConfiguration; baseConfigurationReference = D8B2E911D3B2B604DA0EB63F /* Pods-CocoaPods-iPhone-Storyboard.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = "iPhone-Storyboard/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; @@ -2145,9 +2163,9 @@ isa = XCBuildConfiguration; baseConfigurationReference = 882BE0937534429CE9BABA74 /* Pods-CocoaPods-ModalForm.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEBUG_INFORMATION_FORMAT = dwarf; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = ModalForm/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.1; @@ -2162,9 +2180,9 @@ isa = XCBuildConfiguration; baseConfigurationReference = 292F6DB962486540B88D73A4 /* Pods-CocoaPods-ModalForm.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = ModalForm/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.1; @@ -2178,6 +2196,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -2187,8 +2206,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -2197,6 +2218,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -2220,6 +2242,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -2229,8 +2252,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -2238,6 +2263,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -2247,6 +2273,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -2255,6 +2282,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = E94753722A8B8892B810A468 /* Pods-CocoaPods-Tests.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CLANG_ENABLE_MODULES = YES; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -2274,6 +2302,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = B0D5AF4466209A639EDA2A38 /* Pods-CocoaPods-Tests.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CLANG_ENABLE_MODULES = YES; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = Tests/Info.plist; @@ -2288,9 +2317,9 @@ isa = XCBuildConfiguration; baseConfigurationReference = E68822A9986A456096C76399 /* Pods-CocoaPods-LoginDemo.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEBUG_INFORMATION_FORMAT = dwarf; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = LoginDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.1; @@ -2305,9 +2334,9 @@ isa = XCBuildConfiguration; baseConfigurationReference = D022D2A592F71840B31E840F /* Pods-CocoaPods-LoginDemo.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "$(inherited)"; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = LoginDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.1; diff --git a/Demo.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme b/Demo.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme index 13f90983..bccce122 100644 --- a/Demo.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +++ b/Demo.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme @@ -1,6 +1,6 @@ 0) { + self.segment.accessibilityLabel = field.accessibilityLabel; + } else { + self.segment.accessibilityLabel = self.headingLabel.text; + } +} + +#pragma mark - Layout + +- (void)layoutSubviews { + [super layoutSubviews]; + + self.segment.frame = [self segmentFrame]; +} + +- (CGRect)segmentFrame { + CGFloat marginX = FORMTextFieldCellMarginX; + CGFloat marginTop = FORMFieldCellMarginTop; + CGFloat marginBotton = FORMFieldCellMarginBottom; + + CGFloat width = CGRectGetWidth(self.frame) - (marginX * 2); + CGFloat height = CGRectGetHeight(self.frame) - marginTop - marginBotton; + CGRect frame = CGRectMake(marginX, marginTop, width, height); + + return frame; +} + +#pragma mark - Actions + +- (void)segmentAction:(id)sender { + FORMFieldValue *value = [self.field.values objectAtIndex:[sender selectedSegmentIndex]]; + self.field.value = value; + + if ([self.delegate respondsToSelector:@selector(fieldCell:updatedWithField:)]) { + [self.delegate fieldCell:self updatedWithField:self.field]; + } +} + +#pragma mark - Styling + +- (void)setLabelFont:(UIFont *)labelFont { + NSString *styleFont = [self.field.styles valueForKey:FORMSegmentLabelFontKey]; + NSString *styleFontSize = [self.field.styles valueForKey:FORMSegmentLabelFontSizeKey]; + if ([styleFont length] > 0) { + if ([styleFontSize length] > 0) { + labelFont = [UIFont fontWithName:styleFont size:[styleFontSize floatValue]]; + } else { + labelFont = [UIFont fontWithName:styleFont size:labelFont.pointSize]; + } + } + + NSDictionary *attributes = [NSDictionary dictionaryWithObject:labelFont forKey:NSFontAttributeName]; + [self.segment setTitleTextAttributes:attributes forState:UIControlStateNormal]; +} + +- (void)setTintColor:(UIColor *)tintColor { + NSString *style = [self.field.styles valueForKey:FORMSegmentTintColorKey]; + if ([style length] > 0) { + tintColor = [[UIColor alloc] initWithHex:style]; + } + + self.segment.tintColor = tintColor; +} + +- (void)setBackgroundColor:(UIColor *)backgroundColor { + NSString *style = [self.field.styles valueForKey:FORMSegmentBackgroundColorKey]; + if ([style length] > 0) { + backgroundColor = [[UIColor alloc] initWithHex:style]; + } + + self.segment.backgroundColor = backgroundColor; +} + +@end diff --git a/Source/FORMDataSource.m b/Source/FORMDataSource.m index d367f3eb..0a674050 100755 --- a/Source/FORMDataSource.m +++ b/Source/FORMDataSource.m @@ -8,6 +8,7 @@ #import "FORMDateFieldCell.h" #import "FORMButtonFieldCell.h" #import "FORMSpacerFieldCell.h" +#import "FORMSegmentFieldCell.h" #import "FORMFieldValue.h" #import "HYPParsedRelationship.h" @@ -187,7 +188,13 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView [collectionView registerClass:[FORMSpacerFieldCell class] forCellWithReuseIdentifier:identifier]; break; - + + case FORMFieldTypeSegment: + identifier = [NSString stringWithFormat:@"%@-%@", FORMSegmentFieldCellIdentifier, field.fieldID]; + [collectionView registerClass:[FORMSegmentFieldCell class] + forCellWithReuseIdentifier:identifier]; + break; + case FORMFieldTypeCustom: abort(); } diff --git a/Source/FORMDefaultStyle.m b/Source/FORMDefaultStyle.m index 3ad22fe2..3355f1f6 100755 --- a/Source/FORMDefaultStyle.m +++ b/Source/FORMDefaultStyle.m @@ -9,6 +9,7 @@ #import "FORMFieldValuesTableViewHeader.h" #import "FORMTextFieldCell.h" #import "FORMButtonFieldCell.h" +#import "FORMSegmentFieldCell.h" #import "FORMBaseFieldCell.h" @import Hex; @@ -98,6 +99,11 @@ + (void)applyStyle { [[FORMTextFieldCell appearance] setTooltipLabelFont:[UIFont fontWithName:@"AvenirNext-Medium" size:14.0]]; [[FORMTextFieldCell appearance] setTooltipLabelTextColor:[[UIColor alloc] initWithHex:@"97591D"]]; [[FORMTextFieldCell appearance] setTooltipBackgroundColor:[[UIColor alloc] initWithHex:@"FDFD54"]]; + + [[FORMSegmentFieldCell appearance] setLabelFont:[UIFont fontWithName:@"AvenirNext-DemiBold" size:16.0]]; + [[FORMSegmentFieldCell appearance] setBackgroundColor:[[UIColor alloc] initWithHex:@"FFFFFF"]]; + [[FORMSegmentFieldCell appearance] setTintColor:[[UIColor alloc] initWithHex:@"3DAFEB"]]; + } @end diff --git a/Source/Models/FORMField.h b/Source/Models/FORMField.h index 934ee789..3764da8c 100755 --- a/Source/Models/FORMField.h +++ b/Source/Models/FORMField.h @@ -18,6 +18,7 @@ typedef NS_ENUM(NSInteger, FORMFieldType) { FORMFieldTypeButton, FORMFieldTypeSpacer, FORMFieldTypeCount, + FORMFieldTypeSegment, FORMFieldTypeCustom }; diff --git a/Source/Models/FORMField.m b/Source/Models/FORMField.m index 0cf381ae..f67f8312 100755 --- a/Source/Models/FORMField.m +++ b/Source/Models/FORMField.m @@ -140,6 +140,7 @@ - (void)setValue:(id)fieldValue { case FORMFieldTypeSelect: case FORMFieldTypeButton: case FORMFieldTypeSpacer: + case FORMFieldTypeSegment: case FORMFieldTypeCustom: break; } @@ -180,6 +181,7 @@ - (id)rawFieldValue { case FORMFieldTypeButton: case FORMFieldTypeSpacer: + case FORMFieldTypeSegment: case FORMFieldTypeCustom: return nil; } @@ -253,6 +255,8 @@ - (FORMFieldType)typeFromTypeString:(NSString *)typeString { return FORMFieldTypeButton; } else if ([typeString isEqualToString:@"spacer"]) { return FORMFieldTypeSpacer; + } else if ([typeString isEqualToString:@"segment"]) { + return FORMFieldTypeSegment; } else { return FORMFieldTypeCustom; } diff --git a/Tests/FORMDataSourceTests.m b/Tests/FORMDataSourceTests.m index 236d7d13..2b56fc5c 100755 --- a/Tests/FORMDataSourceTests.m +++ b/Tests/FORMDataSourceTests.m @@ -937,6 +937,16 @@ - (void)testStyleFields { XCTAssertEqualObjects([buttonField.styles objectForKey:@"font"], @"AvenirNext-DemiBold"); XCTAssertEqualObjects([buttonField.styles objectForKey:@"font_size"], @"16.0"); + // Segment Field Styles + FORMField *segmentField = [dataSource fieldWithID:@"styled_segment" includingHiddenFields:NO]; + XCTAssertNotNil(segmentField); + + [dataSource fieldCell:nil updatedWithField:segmentField]; + XCTAssertNotNil(segmentField.styles); + XCTAssertEqualObjects([segmentField.styles objectForKey:@"tint_color"], @"#FF0000"); + XCTAssertEqualObjects([segmentField.styles objectForKey:@"font"], @"AvenirNext-DemiBold"); + XCTAssertEqualObjects([segmentField.styles objectForKey:@"font_size"], @"16.0"); + // Text Field Styles FORMField *textField = [dataSource fieldWithID:@"styled_text_field" includingHiddenFields:NO]; XCTAssertNotNil(textField); diff --git a/Tests/FORMDataTests.m b/Tests/FORMDataTests.m index 70b2333e..411d8427 100755 --- a/Tests/FORMDataTests.m +++ b/Tests/FORMDataTests.m @@ -811,6 +811,18 @@ - (void)testInitializatingACounterFieldWithAValueInTheJSON { XCTAssertEqualObjects(formData.values[@"count"], @"1"); } + +- (void)testInitializatingASegmentFieldWithAValueInTheJSON { + NSArray *JSON = [NSJSONSerialization JSONObjectWithContentsOfFile:@"segment-field.json" + inBundle:[NSBundle bundleForClass:[self class]]]; + + FORMData *formData = [[FORMData alloc] initWithJSON:JSON + initialValues:nil + disabledFieldIDs:nil + disabled:NO]; + + XCTAssertEqualObjects(formData.values[@"segment"], @"part_1"); +} - (void)testFieldStyles { NSArray *JSON = [NSJSONSerialization JSONObjectWithContentsOfFile:@"styled-fields.json" @@ -841,6 +853,15 @@ - (void)testFieldStyles { XCTAssertEqualObjects([field.styles objectForKey:@"font"], @"AvenirNext-DemiBold"); XCTAssertEqualObjects([field.styles objectForKey:@"font_size"], @"16.0"); + // Segment Styles + field = [formData fieldWithID:@"styled_segment" includingHiddenFields:NO]; + XCTAssertNotNil(field); + XCTAssertNotNil(field.styles); + + XCTAssertEqualObjects([field.styles objectForKey:@"tint_color"], @"#FF0000"); + XCTAssertEqualObjects([field.styles objectForKey:@"font"], @"AvenirNext-DemiBold"); + XCTAssertEqualObjects([field.styles objectForKey:@"font_size"], @"16.0"); + // Text Field Styles field = [formData fieldWithID:@"styled_text_field" includingHiddenFields:NO]; XCTAssertNotNil(field); diff --git a/Tests/FORMFieldTests.m b/Tests/FORMFieldTests.m index a2b594dd..84bef930 100755 --- a/Tests/FORMFieldTests.m +++ b/Tests/FORMFieldTests.m @@ -158,6 +158,34 @@ - (void)testInitWithDictionary { XCTAssertTrue(field.disabled); XCTAssertNil(field.validation); XCTAssertFalse(field.hidden); + + values = @[ + @{@"id": @"part_1", @"title": @"Part 1"}, + @{@"id": @"part_2", @"title": @"Part 2"}, + ]; + field = [[FORMField alloc] initWithDictionary:@{@"id": @"segment_control", + @"title": @"Segment Control", + @"accessibility_label": @"Accessibility label", + @"type": @"segment", + @"values":values, + @"value":@"part_1", + @"size": @{@"width": @30, + @"height": @1} + } + position:1 + disabled:NO + disabledFieldsIDs:@[@"segment_control"]]; + XCTAssertNotNil(field); + XCTAssertEqualObjects(field.typeString, @"segment"); + XCTAssertTrue(field.type == FORMFieldTypeSegment); + + XCTAssertEqualObjects(field.value, @"part_1"); + XCTAssertEqualObjects(field.accessibilityLabel, @"Accessibility label"); + + XCTAssertTrue(CGSizeEqualToSize(field.size, CGSizeMake(30, 1))); + XCTAssertTrue(field.disabled); + XCTAssertNil(field.validation); + XCTAssertFalse(field.hidden); } - (void)testInputValidator { diff --git a/Tests/JSONs/segment-field.json b/Tests/JSONs/segment-field.json new file mode 100755 index 00000000..b83755d4 --- /dev/null +++ b/Tests/JSONs/segment-field.json @@ -0,0 +1,34 @@ +[ + { + "id": "group", + "title": "Group", + "sections": [ + { + "id": "section", + "fields": [ + { + "id": "segment", + "title": "My Segment", + "type": "segment", + "value": "part_1", + "values":[ + { + "id":"part_1", + "title":"Part 1", + "default":true, + }, + { + "id":"part_2", + "title":"Part 2", + } + ], + "size": { + "width": 25, + "height": 1 + } + } + ] + } + ] + } +] diff --git a/Tests/JSONs/styled-fields.json b/Tests/JSONs/styled-fields.json index 89de2411..6f316b7d 100755 --- a/Tests/JSONs/styled-fields.json +++ b/Tests/JSONs/styled-fields.json @@ -85,6 +85,31 @@ "minus_button_color":"#FF0000", "plus_button_color":"#FF3333", } + }, + { + "id":"styled_segment", + "title":"Styled Segment", + "type":"segment", + "styles":{ + "font":"AvenirNext-DemiBold", + "font_size":"16.0", + "tint_color":"#FF0000" + }, + "values":[ + { + "id":"part_1", + "title":"Part 1", + "default":true, + }, + { + "id":"part_2", + "title":"Part 2", + } + ], + "size":{ + "width":40, + "height":1 + }, } ] }