Skip to content

Commit ec29724

Browse files
committed
Add support for left & right views
Fixes stephsharp#18
1 parent 28b2797 commit ec29724

11 files changed

Lines changed: 151 additions & 1 deletion

File tree

MaterialTextField/MFTextField.m

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ - (void)removeErrorLabel
642642
- (CGRect)textRectForBounds:(CGRect)bounds
643643
{
644644
CGRect superRect = [super textRectForBounds:bounds];
645-
CGRect rect = CGRectMake(self.textPadding.width,
645+
CGRect rect = CGRectMake(superRect.origin.x + self.textPadding.width,
646646
[self adjustedYPositionForTextRect],
647647
superRect.size.width - (2.0 * self.textPadding.width),
648648
self.font.lineHeight);
@@ -677,6 +677,22 @@ - (CGRect)clearButtonRectForBounds:(CGRect)bounds
677677
return clearButtonRect;
678678
}
679679

680+
- (CGRect)rightViewRectForBounds:(CGRect)bounds
681+
{
682+
CGRect rightViewRect = [super rightViewRectForBounds:bounds];
683+
rightViewRect.origin.y = CGRectGetMidY(_textRect) - (rightViewRect.size.height / 2.0f);
684+
685+
return rightViewRect;
686+
}
687+
688+
- (CGRect)leftViewRectForBounds:(CGRect)bounds
689+
{
690+
CGRect leftViewRect = [super leftViewRectForBounds:bounds];
691+
leftViewRect.origin.y = CGRectGetMidY(_textRect) - (leftViewRect.size.height / 2.0f);
692+
693+
return leftViewRect;
694+
}
695+
680696
# pragma mark - UIView
681697

682698
- (CGSize)intrinsicContentSize

MaterialTextFieldDemo/MaterialTextFieldDemo/Base.lproj/Main.storyboard

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@
5353
<userDefinedRuntimeAttribute type="color" keyPath="placeholderColor">
5454
<color key="value" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
5555
</userDefinedRuntimeAttribute>
56+
<userDefinedRuntimeAttribute type="size" keyPath="textPadding">
57+
<size key="value" width="20" height="8"/>
58+
</userDefinedRuntimeAttribute>
59+
<userDefinedRuntimeAttribute type="size" keyPath="errorPadding">
60+
<size key="value" width="20" height="8"/>
61+
</userDefinedRuntimeAttribute>
5662
</userDefinedRuntimeAttributes>
63+
<connections>
64+
<action selector="textFieldDidChange:" destination="BYZ-38-t0r" eventType="editingChanged" id="uMx-3J-4yS"/>
65+
</connections>
5766
</textField>
5867
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="number" textAlignment="right" adjustsFontSizeToFit="NO" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="gNx-E7-aGq" customClass="MFTextField">
5968
<rect key="frame" x="16" y="20" width="343" height="60"/>
@@ -109,6 +118,7 @@
109118
<connections>
110119
<outlet property="textField1" destination="gNx-E7-aGq" id="1pI-Mq-qvh"/>
111120
<outlet property="textField2" destination="vrI-fI-vIo" id="e8w-3k-NaW"/>
121+
<outlet property="textField4" destination="A1d-5c-S25" id="k4X-gw-qB1"/>
112122
<outlet property="textField5" destination="Z0L-Ka-jzP" id="lDR-gK-uuK"/>
113123
</connections>
114124
</viewController>

MaterialTextFieldDemo/MaterialTextFieldDemo/Images.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "20x20",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "20x20",
11+
"scale" : "3x"
12+
},
313
{
414
"idiom" : "iphone",
515
"size" : "29x29",
@@ -30,6 +40,16 @@
3040
"size" : "60x60",
3141
"scale" : "3x"
3242
},
43+
{
44+
"idiom" : "ipad",
45+
"size" : "20x20",
46+
"scale" : "1x"
47+
},
48+
{
49+
"idiom" : "ipad",
50+
"size" : "20x20",
51+
"scale" : "2x"
52+
},
3353
{
3454
"idiom" : "ipad",
3555
"size" : "29x29",
@@ -59,6 +79,16 @@
5979
"idiom" : "ipad",
6080
"size" : "76x76",
6181
"scale" : "2x"
82+
},
83+
{
84+
"idiom" : "ipad",
85+
"size" : "83.5x83.5",
86+
"scale" : "2x"
87+
},
88+
{
89+
"idiom" : "ios-marketing",
90+
"size" : "1024x1024",
91+
"scale" : "1x"
6292
}
6393
],
6494
"info" : {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"filename" : "eye@2x.png",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"filename" : "eye@3x.png",
15+
"scale" : "3x"
16+
}
17+
],
18+
"info" : {
19+
"version" : 1,
20+
"author" : "xcode"
21+
}
22+
}
1.38 KB
Loading
2.01 KB
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"filename" : "lock@2x.png",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"filename" : "lock@3x.png",
15+
"scale" : "3x"
16+
}
17+
],
18+
"info" : {
19+
"version" : 1,
20+
"author" : "xcode"
21+
}
22+
}
1.32 KB
Loading
1.86 KB
Loading

0 commit comments

Comments
 (0)