Skip to content
This repository was archived by the owner on Jan 3, 2024. It is now read-only.

Commit 4defe62

Browse files
densacybergrind
authored andcommitted
Add ability set attributed string and icons into dropdown (#6)
* Add ability set attributed string into dropdown Add ability set icon into dropdown * Code review * Add Snapshot tests Add test for NSAttributedString * Add Snapshot images for iOS 10
1 parent 62f8b88 commit 4defe62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+978
-450
lines changed

Example/Pods/Pods.xcodeproj/project.pbxproj

+442-428
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/TPSDropDown/TPSDropDown-umbrella.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/TPSDropDown.xcodeproj/project.pbxproj

+14
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; };
2222
62376C80B690B4F0A3184C73 /* Pods_TPSDropDown_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4F19BBE24005C855CBF36D78 /* Pods_TPSDropDown_Example.framework */; };
2323
873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; };
24+
990EF5BE1E150FDB00FCEC9B /* TPSNSAttributedStringTPSDropDownItemTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 990EF5BD1E150FDB00FCEC9B /* TPSNSAttributedStringTPSDropDownItemTests.m */; };
25+
990EF5C01E1519FF00FCEC9B /* TPSDropDownSnapshotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 990EF5BF1E1519FF00FCEC9B /* TPSDropDownSnapshotTests.m */; };
26+
990EF5C11E151B9400FCEC9B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; };
27+
990EF5D01E16521000FCEC9B /* TPSViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5A6195388D20070C39A /* TPSViewController.m */; };
28+
990EF5D11E16738600FCEC9B /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5A8195388D20070C39A /* Images.xcassets */; };
2429
B8198F0F1DF852FA00C8AD1B /* TPSNSStringTPSDropDownItemTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B8198ED61DF83ED900C8AD1B /* TPSNSStringTPSDropDownItemTests.m */; };
2530
B8198F101DF852FA00C8AD1B /* TPSDropDownTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B8198F091DF8425700C8AD1B /* TPSDropDownTests.m */; };
2631
B8198F111DF852FA00C8AD1B /* TPSRoundDropDownTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B8198F0B1DF8426600C8AD1B /* TPSRoundDropDownTests.m */; };
@@ -70,6 +75,8 @@
7075
6C4421A98A3E310918D7A19F /* Pods-TPSDropDown_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TPSDropDown_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-TPSDropDown_Tests/Pods-TPSDropDown_Tests.release.xcconfig"; sourceTree = "<group>"; };
7176
6F8338D75C58CC4E77EDBF22 /* Pods_TPSDropDown_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TPSDropDown_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7277
873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
78+
990EF5BD1E150FDB00FCEC9B /* TPSNSAttributedStringTPSDropDownItemTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPSNSAttributedStringTPSDropDownItemTests.m; sourceTree = "<group>"; };
79+
990EF5BF1E1519FF00FCEC9B /* TPSDropDownSnapshotTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPSDropDownSnapshotTests.m; sourceTree = "<group>"; };
7380
A5BCF57DBA8D77AB80CA46FB /* Pods-TPSDropDown_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TPSDropDown_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-TPSDropDown_Example/Pods-TPSDropDown_Example.release.xcconfig"; sourceTree = "<group>"; };
7481
B8198ED61DF83ED900C8AD1B /* TPSNSStringTPSDropDownItemTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPSNSStringTPSDropDownItemTests.m; sourceTree = "<group>"; };
7582
B8198F091DF8425700C8AD1B /* TPSDropDownTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPSDropDownTests.m; sourceTree = "<group>"; };
@@ -175,9 +182,11 @@
175182
children = (
176183
6003F5B6195388D20070C39A /* Supporting Files */,
177184
B8198ED61DF83ED900C8AD1B /* TPSNSStringTPSDropDownItemTests.m */,
185+
990EF5BD1E150FDB00FCEC9B /* TPSNSAttributedStringTPSDropDownItemTests.m */,
178186
B8198F091DF8425700C8AD1B /* TPSDropDownTests.m */,
179187
B8198F0B1DF8426600C8AD1B /* TPSRoundDropDownTests.m */,
180188
B8198F0D1DF8427300C8AD1B /* TPSSquareDropDownTests.m */,
189+
990EF5BF1E1519FF00FCEC9B /* TPSDropDownSnapshotTests.m */,
181190
);
182191
path = Tests;
183192
sourceTree = "<group>";
@@ -311,8 +320,10 @@
311320
buildActionMask = 2147483647;
312321
files = (
313322
B8198F171DF85DDD00C8AD1B /* proximanova-semibold-webfont.ttf in Resources */,
323+
990EF5D11E16738600FCEC9B /* Images.xcassets in Resources */,
314324
B8198F181DF85DDF00C8AD1B /* theserif-regular.ttf in Resources */,
315325
6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */,
326+
990EF5C11E151B9400FCEC9B /* Main.storyboard in Resources */,
316327
);
317328
runOnlyForDeploymentPostprocessing = 0;
318329
};
@@ -426,10 +437,13 @@
426437
isa = PBXSourcesBuildPhase;
427438
buildActionMask = 2147483647;
428439
files = (
440+
990EF5C01E1519FF00FCEC9B /* TPSDropDownSnapshotTests.m in Sources */,
429441
B8198F0F1DF852FA00C8AD1B /* TPSNSStringTPSDropDownItemTests.m in Sources */,
430442
B8198F101DF852FA00C8AD1B /* TPSDropDownTests.m in Sources */,
431443
B8198F111DF852FA00C8AD1B /* TPSRoundDropDownTests.m in Sources */,
444+
990EF5D01E16521000FCEC9B /* TPSViewController.m in Sources */,
432445
B8198F121DF852FA00C8AD1B /* TPSSquareDropDownTests.m in Sources */,
446+
990EF5BE1E150FDB00FCEC9B /* TPSNSAttributedStringTPSDropDownItemTests.m in Sources */,
433447
);
434448
runOnlyForDeploymentPostprocessing = 0;
435449
};

Example/TPSDropDown.xcodeproj/xcshareddata/xcschemes/TPSDropDown-Example.xcscheme

+15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@
3838
ReferencedContainer = "container:TPSDropDown.xcodeproj">
3939
</BuildableReference>
4040
</TestableReference>
41+
<TestableReference
42+
skipped = "NO">
43+
<BuildableReference
44+
BuildableIdentifier = "primary"
45+
BlueprintIdentifier = "990EF5C51E1556A200FCEC9B"
46+
BuildableName = "TPSDropDown_ExampleUITests.xctest"
47+
BlueprintName = "TPSDropDown_ExampleUITests"
48+
ReferencedContainer = "container:TPSDropDown.xcodeproj">
49+
</BuildableReference>
50+
</TestableReference>
4151
</Testables>
4252
<MacroExpansion>
4353
<BuildableReference
@@ -77,6 +87,11 @@
7787
value = "disable"
7888
isEnabled = "YES">
7989
</EnvironmentVariable>
90+
<EnvironmentVariable
91+
key = "FB_REFERENCE_IMAGE_DIR"
92+
value = "$(SOURCE_ROOT)/Tests/ReferenceImages"
93+
isEnabled = "YES">
94+
</EnvironmentVariable>
8095
</EnvironmentVariables>
8196
<AdditionalOptions>
8297
</AdditionalOptions>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "1.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "2.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "3.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "4.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}

Example/TPSDropDown/Main.storyboard

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11761" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Vth-xD-XMU">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Vth-xD-XMU">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
7-
<deployment identifier="iOS"/>
87
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
98
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
109
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -13,7 +12,7 @@
1312
<!--View Controller-->
1413
<scene sceneID="wQg-tq-qST">
1514
<objects>
16-
<viewController id="whP-gf-Uak" customClass="TPSViewController" sceneMemberID="viewController">
15+
<viewController storyboardIdentifier="TPSViewController" id="whP-gf-Uak" customClass="TPSViewController" sceneMemberID="viewController">
1716
<layoutGuides>
1817
<viewControllerLayoutGuide type="top" id="uEw-UM-LJ8"/>
1918
<viewControllerLayoutGuide type="bottom" id="Mvr-aV-6Um"/>
@@ -59,17 +58,39 @@
5958
<constraint firstItem="So2-eU-acY" firstAttribute="leading" secondItem="m0b-no-Hj2" secondAttribute="trailing" constant="8" id="wXL-f8-Ll3"/>
6059
</constraints>
6160
</view>
61+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="U82-vx-SRE">
62+
<rect key="frame" x="16" y="140" width="343" height="60"/>
63+
<subviews>
64+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="MH8-ED-FVN" customClass="TPSDropDown">
65+
<rect key="frame" x="8" y="8" width="327" height="44"/>
66+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
67+
<color key="tintColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
68+
</view>
69+
</subviews>
70+
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
71+
<constraints>
72+
<constraint firstItem="MH8-ED-FVN" firstAttribute="top" secondItem="U82-vx-SRE" secondAttribute="top" constant="8" id="Ffw-CT-mwF"/>
73+
<constraint firstAttribute="trailing" secondItem="MH8-ED-FVN" secondAttribute="trailing" constant="8" id="Yr3-3H-Nfa"/>
74+
<constraint firstAttribute="height" constant="60" id="evh-b6-Ass"/>
75+
<constraint firstAttribute="bottom" secondItem="MH8-ED-FVN" secondAttribute="bottom" constant="8" id="gCS-Ll-rLg"/>
76+
<constraint firstItem="MH8-ED-FVN" firstAttribute="leading" secondItem="U82-vx-SRE" secondAttribute="leading" constant="8" id="gyK-WL-sWw"/>
77+
</constraints>
78+
</view>
6279
</subviews>
6380
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
6481
<constraints>
82+
<constraint firstItem="U82-vx-SRE" firstAttribute="leading" secondItem="TpU-gO-2f1" secondAttribute="leading" constant="16" id="4oi-mr-MtV"/>
6583
<constraint firstItem="xy1-PW-lKR" firstAttribute="top" secondItem="uEw-UM-LJ8" secondAttribute="bottom" constant="20" id="5Af-7V-lhp"/>
84+
<constraint firstAttribute="trailing" secondItem="U82-vx-SRE" secondAttribute="trailing" constant="16" id="6jE-qp-8eZ"/>
6685
<constraint firstItem="xy1-PW-lKR" firstAttribute="leading" secondItem="TpU-gO-2f1" secondAttribute="leadingMargin" id="ZiI-fS-htW"/>
86+
<constraint firstItem="U82-vx-SRE" firstAttribute="top" secondItem="xy1-PW-lKR" secondAttribute="bottom" constant="8" id="eJ5-QC-vWe"/>
6787
<constraint firstAttribute="trailingMargin" secondItem="xy1-PW-lKR" secondAttribute="trailing" id="yuE-g4-chL"/>
6888
</constraints>
6989
</view>
7090
<navigationItem key="navigationItem" id="oWX-41-S0W"/>
7191
<connections>
7292
<outlet property="dropDown" destination="m0b-no-Hj2" id="a5Y-5p-t0C"/>
93+
<outlet property="payDropDown" destination="MH8-ED-FVN" id="K9L-b7-Uk2"/>
7394
<outlet property="roundDropDown" destination="pTZ-Gf-Q54" id="wbR-LX-lvT"/>
7495
<outlet property="squareDropDown" destination="So2-eU-acY" id="ZZ3-SW-VLK"/>
7596
</connections>
@@ -83,7 +104,7 @@
83104
<objects>
84105
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="Vth-xD-XMU" sceneMemberID="viewController">
85106
<toolbarItems/>
86-
<navigationBar key="navigationBar" contentMode="scaleToFill" id="A2c-r2-vFJ">
107+
<navigationBar key="navigationBar" contentMode="scaleToFill" misplaced="YES" id="A2c-r2-vFJ">
87108
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
88109
<autoresizingMask key="autoresizingMask"/>
89110
</navigationBar>

Example/TPSDropDown/TPSViewController.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
//
88

99
@import UIKit;
10+
@import TPSDropDown;
1011

1112
@interface TPSViewController : UIViewController
12-
13+
- (void)openDropDown;
14+
- (void)openPaymentDropDown;
15+
- (void)closeAllDropDowns;
1316
@end

Example/TPSDropDown/TPSViewController.m

+49-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,32 @@
1212
#import <TPSDropDown/TPSRoundDropDown.h>
1313
#import <TPSDropDown/TPSSquareDropDown.h>
1414

15-
@interface TPSViewController ()
15+
@interface TPSDropDownPayItem : NSObject <TPSDropDownItem>
16+
@property (nonatomic, copy) NSString *title;
17+
@property (nonatomic, copy) NSString *iconName;
18+
@end
19+
20+
@implementation TPSDropDownPayItem
1621

22+
- (instancetype)initWithTitle:(NSString*)title iconName:(NSString*)iconName {
23+
if (self = [super init]) {
24+
self.title = title;
25+
self.iconName = iconName;
26+
}
27+
return self;
28+
}
29+
30+
- (NSAttributedString *)attributedTitle {
31+
return nil;
32+
}
33+
34+
@end
35+
36+
@interface TPSViewController ()
1737
@property (weak, nonatomic) IBOutlet TPSDropDown *dropDown;
1838
@property (weak, nonatomic) IBOutlet TPSSquareDropDown *squareDropDown;
1939
@property (weak, nonatomic) IBOutlet TPSRoundDropDown *roundDropDown;
20-
40+
@property (weak, nonatomic) IBOutlet TPSDropDown *payDropDown;
2141
@end
2242

2343
@implementation TPSViewController
@@ -29,12 +49,38 @@ - (void)viewDidLoad {
2949

3050
self.dropDown.items = @[@"One", @"Two", @"Three"];
3151
self.dropDown.selectedItemIndex = 0;
32-
52+
3353
self.squareDropDown.items = @[@"One", @"Two", @"Three"];
3454
self.squareDropDown.selectedItemIndex = 0;
3555

3656
self.roundDropDown.items = @[@"One", @"Two", @"Three"];
3757
self.roundDropDown.selectedItemIndex = 0;
58+
59+
TPSDropDownPayItem *visaItem = [[TPSDropDownPayItem alloc] initWithTitle:@"Visa" iconName:@"1"];
60+
TPSDropDownPayItem *masterItem = [[TPSDropDownPayItem alloc] initWithTitle:@"Master Card" iconName:@"2"];
61+
TPSDropDownPayItem *maestroItem = [[TPSDropDownPayItem alloc] initWithTitle:@"PayPal" iconName:@"3"];
62+
TPSDropDownPayItem *payPalItem = [[TPSDropDownPayItem alloc] initWithTitle:@"Maestro" iconName:@"4"];
63+
64+
self.payDropDown.items = @[visaItem, masterItem, payPalItem, maestroItem];
65+
self.payDropDown.selectedItemIndex = 0;
66+
}
67+
68+
#pragma mark - Open / Close
69+
70+
- (void)openDropDown {
71+
[self.dropDown openDropDown:NO];
72+
}
73+
74+
- (void)openPaymentDropDown {
75+
[self.payDropDown openDropDown:NO];
76+
}
77+
78+
// Close dropdowns for Snapshot tests
79+
- (void)closeAllDropDowns {
80+
[self.dropDown closeDropDown:NO];
81+
[self.squareDropDown closeDropDown:NO];
82+
[self.roundDropDown closeDropDown:NO];
83+
[self.payDropDown closeDropDown:NO];
3884
}
3985

4086
@end

0 commit comments

Comments
 (0)