File tree Expand file tree Collapse file tree
Example/SMFloatingLabelTextField
SMFloatingLabelTextField/Classes Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,7 +20,8 @@ - (void)viewDidLoad {
2020 [super viewDidLoad ];
2121
2222 NSDictionary *lastNamePlaceholderAttributes = @{NSForegroundColorAttributeName : [UIColor magentaColor ],
23- NSFontAttributeName : [UIFont systemFontOfSize: 14 .0f weight: UIFontWeightBold]
23+ NSFontAttributeName : [UIFont systemFontOfSize: 14 .0f weight: UIFontWeightBold],
24+ NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle),
2425 };
2526 NSAttributedString *lastNamePlaceholder = [[NSAttributedString alloc ] initWithString: @" Last name" attributes: lastNamePlaceholderAttributes];
2627
Original file line number Diff line number Diff line change 88
99Pod ::Spec . new do |s |
1010 s . name = 'SMFloatingLabelTextField'
11- s . version = '0.3.0 '
11+ s . version = '0.3.1 '
1212 s . summary = 'A subclass of UITextField that displays floating placeholder'
1313
1414# This description is used to generate tags and improve search results.
Original file line number Diff line number Diff line change @@ -174,7 +174,23 @@ - (void)setPlaceholder:(NSString *)placeholder {
174174
175175- (void )setAttributedPlaceholder : (NSAttributedString *)attributedPlaceholder {
176176 [super setAttributedPlaceholder: attributedPlaceholder];
177- self.floatingLabel .attributedText = attributedPlaceholder;
177+ self.floatingLabel .attributedText = [self floatingLabelAttributedPlacecholderStringFrom: attributedPlaceholder];
178+ }
179+
180+ - (NSAttributedString *)floatingLabelAttributedPlacecholderStringFrom : (NSAttributedString *)attributedString {
181+ NSMutableAttributedString *mutableAttributedString = [attributedString mutableCopy ];
182+ NSRange wholeStringRange = NSMakeRange (0 , mutableAttributedString.length );
183+ [mutableAttributedString removeAttribute: NSFontAttributeName range: wholeStringRange];
184+ [mutableAttributedString removeAttribute: NSForegroundColorAttributeName range: wholeStringRange];
185+
186+ [mutableAttributedString addAttribute: NSFontAttributeName value: self .floatingLabelFont range: wholeStringRange];
187+ if (self.displayFloatingPlaceholder ) {
188+ [mutableAttributedString addAttribute: NSForegroundColorAttributeName value: self .floatingLabelActiveColor range: wholeStringRange];
189+ } else {
190+ [mutableAttributedString addAttribute: NSForegroundColorAttributeName value: self .floatingLabelPassiveColor range: wholeStringRange];
191+ }
192+
193+ return [mutableAttributedString copy ];
178194}
179195
180196#pragma mark - dealloc
You can’t perform that action at this time.
0 commit comments