-
效果说明 :
-
当前编辑的占位文字会变为醒目色
-
失去编辑状态就会恢复
-
效果展示 :
代码 :
- 添加监听textField的状态
[self addTarget:self action:@selector(beginEdite) forControlEvents:UIControlEventEditingDidBegin];
[self addTarget:self action:@selector(endEdite ) forControlEvents:UIControlEventEditingDidEnd];
2.实现监听动作
- (void)beginEdite {
[self setValue:[UIColor whiteColor] forKeyPath:YSPlaceholderText];
}
- (void)endEdite {
[self setValue:[UIColor colorWithRed:206/255 green:206/255 blue:206/255 alpha:0.2] forKeyPath:YSPlaceholderText];
}
3.解释宏定义 :
static NSString * const YSPlaceholderText = @"placeholderLabel.textColor";
4.运行时查看textField的私有属性
- (void)getIvar {
unsigned int count;
Ivar * list = class_copyIvarList([UITextField class], &count);
for (int i = 0; i <count; i ++) {
NSLog(@"%s",ivar_getName(list[i]));
}
}
5.打印如下 :
2016-09-10 15:40:07.334 框架搭建[75988:4198350] _textStorage
2016-09-10 15:40:07.334 框架搭建[75988:4198350] _borderStyle
2016-09-10 15:40:07.334 框架搭建[75988:4198350] _minimumFontSize
2016-09-10 15:40:07.335 框架搭建[75988:4198350] _delegate
2016-09-10 15:40:07.335 框架搭建[75988:4198350] _background
2016-09-10 15:40:07.335 框架搭建[75988:4198350] _disabledBackground
2016-09-10 15:40:07.335 框架搭建[75988:4198350] _clearButtonMode
2016-09-10 15:40:07.335 框架搭建[75988:4198350] _leftView
2016-09-10 15:40:07.335 框架搭建[75988:4198350] _leftViewMode
2016-09-10 15:40:07.335 框架搭建[75988:4198350] _rightView
2016-09-10 15:40:07.335 框架搭建[75988:4198350] _rightViewMode
2016-09-10 15:40:07.336 框架搭建[75988:4198350] _traits
2016-09-10 15:40:07.336 框架搭建[75988:4198350] _nonAtomTraits
2016-09-10 15:40:07.336 框架搭建[75988:4198350] _fullFontSize
2016-09-10 15:40:07.336 框架搭建[75988:4198350] _padding
2016-09-10 15:40:07.336 框架搭建[75988:4198350] _selectionRangeWhenNotEditing
2016-09-10 15:40:07.336 框架搭建[75988:4198350] _scrollXOffset
2016-09-10 15:40:07.336 框架搭建[75988:4198350] _scrollYOffset
2016-09-10 15:40:07.336 框架搭建[75988:4198350] _progress
2016-09-10 15:40:07.337 框架搭建[75988:4198350] _clearButton
2016-09-10 15:40:07.337 框架搭建[75988:4198350] _clearButtonOffset
2016-09-10 15:40:07.337 框架搭建[75988:4198350] _leftViewOffset
2016-09-10 15:40:07.337 框架搭建[75988:4198350] _rightViewOffset
2016-09-10 15:40:07.337 框架搭建[75988:4198350] _backgroundView
2016-09-10 15:40:07.337 框架搭建[75988:4198350] _disabledBackgroundView
2016-09-10 15:40:07.337 框架搭建[75988:4198350] _systemBackgroundView
2016-09-10 15:40:07.338 框架搭建[75988:4198350] _displayLabel
2016-09-10 15:40:07.338 框架搭建[75988:4198350] _placeholderLabel
2016-09-10 15:40:07.338 框架搭建[75988:4198350] _suffixLabel
2016-09-10 15:40:07.338 框架搭建[75988:4198350] _prefixLabel
2016-09-10 15:40:07.338 框架搭建[75988:4198350] _iconView
2016-09-10 15:40:07.338 框架搭建[75988:4198350] _label
2016-09-10 15:40:07.338 框架搭建[75988:4198350] _labelOffset
2016-09-10 15:40:07.338 框架搭建[75988:4198350] _interactionAssistant
2016-09-10 15:40:07.339 框架搭建[75988:4198350] _selectGestureRecognizer
2016-09-10 15:40:07.339 框架搭建[75988:4198350] _inputView
2016-09-10 15:40:07.339 框架搭建[75988:4198350] _inputAccessoryView
2016-09-10 15:40:07.339 框架搭建[75988:4198350] _systemInputViewController
2016-09-10 15:40:07.339 框架搭建[75988:4198350] _atomBackgroundView
2016-09-10 15:40:07.339 框架搭建[75988:4198350] _textFieldFlags
2016-09-10 15:40:07.339 框架搭建[75988:4198350] _deferringBecomeFirstResponder
2016-09-10 15:40:07.339 框架搭建[75988:4198350] _avoidBecomeFirstResponder
2016-09-10 15:40:07.340 框架搭建[75988:4198350] _setSelectionRangeAfterFieldEditorIsAttached
2016-09-10 15:40:07.340 框架搭建[75988:4198350] _animateNextHighlightChange
2016-09-10 15:40:07.340 框架搭建[75988:4198350] _baselineLayoutConstraint
2016-09-10 15:40:07.340 框架搭建[75988:4198350] _baselineLayoutLabel
可以很轻松的找到我们想要的
2016-09-10 15:40:07.338 框架搭建[75988:4198350] _placeholderLabel
属性
然后利用kvc赋值我们想要的颜色!
如果对你有帮助 不胜荣幸
邮箱地址:zh_yes@foxmail.com
网友评论