Skip to content

Commit 01b177c

Browse files
author
Michał Moskała
committed
Added example with setting attributed placeholder.
1 parent 48cd1d8 commit 01b177c

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

Example/Pods/Pods.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/SMFloatingLabelTextField/Main.storyboard

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="whP-gf-Uak">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="whP-gf-Uak">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
47
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
610
</dependencies>
711
<scenes>
812
<!--View Controller-->
@@ -14,35 +18,35 @@
1418
<viewControllerLayoutGuide type="bottom" id="Mvr-aV-6Um"/>
1519
</layoutGuides>
1620
<view key="view" contentMode="scaleToFill" id="TpU-gO-2f1">
17-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
21+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1822
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1923
<subviews>
2024
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="First name" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="O6v-c2-u0k" customClass="SMFloatingLabelTextField">
21-
<rect key="frame" x="16" y="44" width="568" height="50"/>
25+
<rect key="frame" x="16" y="44" width="343" height="50"/>
2226
<constraints>
2327
<constraint firstAttribute="height" constant="50" id="1fl-ep-0yC"/>
2428
</constraints>
2529
<fontDescription key="fontDescription" type="system" pointSize="14"/>
2630
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no"/>
2731
</textField>
2832
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Last name" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="8kl-vL-8WK" customClass="SMFloatingLabelTextField">
29-
<rect key="frame" x="16" y="118" width="568" height="50"/>
33+
<rect key="frame" x="16" y="118" width="343" height="50"/>
3034
<constraints>
3135
<constraint firstAttribute="height" constant="50" id="cB4-bP-zAj"/>
3236
</constraints>
3337
<fontDescription key="fontDescription" type="system" pointSize="14"/>
3438
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no"/>
3539
</textField>
3640
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Address" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="LGP-fL-2tA" customClass="SMFloatingLabelTextField">
37-
<rect key="frame" x="16" y="192" width="568" height="50"/>
41+
<rect key="frame" x="16" y="192" width="343" height="50"/>
3842
<constraints>
3943
<constraint firstAttribute="height" constant="50" id="MSR-z4-5lD"/>
4044
</constraints>
4145
<fontDescription key="fontDescription" type="system" pointSize="14"/>
4246
<textInputTraits key="textInputTraits"/>
4347
</textField>
4448
</subviews>
45-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
49+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
4650
<constraints>
4751
<constraint firstItem="O6v-c2-u0k" firstAttribute="top" secondItem="uEw-UM-LJ8" secondAttribute="bottom" constant="24" id="28A-6h-Tmw"/>
4852
<constraint firstItem="8kl-vL-8WK" firstAttribute="leading" secondItem="TpU-gO-2f1" secondAttribute="leading" constant="16" id="8nD-YM-0aa"/>
@@ -57,6 +61,7 @@
5761
</view>
5862
<connections>
5963
<outlet property="addressTextField" destination="LGP-fL-2tA" id="cuZ-4x-gec"/>
64+
<outlet property="lastNameTextField" destination="8kl-vL-8WK" id="A4c-bg-yH1"/>
6065
</connections>
6166
</viewController>
6267
<placeholder placeholderIdentifier="IBFirstResponder" id="tc2-Qw-aMS" userLabel="First Responder" sceneMemberID="firstResponder"/>

Example/SMFloatingLabelTextField/SMViewController.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@
1111

1212
@interface SMViewController ()
1313
@property (nonatomic, weak) IBOutlet SMFloatingLabelTextField *addressTextField;
14+
@property (nonatomic, weak) IBOutlet SMFloatingLabelTextField *lastNameTextField;
1415
@end
1516

1617
@implementation SMViewController
1718

1819
- (void)viewDidLoad {
1920
[super viewDidLoad];
21+
22+
NSDictionary *lastNamePlaceholderAttributes = @{NSForegroundColorAttributeName: [UIColor magentaColor],
23+
NSFontAttributeName: [UIFont systemFontOfSize:14.0f weight:UIFontWeightBold]
24+
};
25+
NSAttributedString *lastNamePlaceholder = [[NSAttributedString alloc] initWithString:@"Last name" attributes:lastNamePlaceholderAttributes];
26+
27+
[self.lastNameTextField setAttributedPlaceholder:lastNamePlaceholder];
2028
[self.addressTextField setText:@"NYC"];
2129
}
2230

0 commit comments

Comments
 (0)