获取iOS控件的隐藏属性

我们在开发的过程中用到的一些控件,明明一些属性我们一定会用到,但是是查看API就是没有,这个时候一般人会吐槽一下苹果;随后就是选择自己封装或者使用其他的实现方式来实现 。但是好多时候从网上搜出来的时候,人家大多都是通过KVC实现,这时候我就想人家咋获得的这些属性,我们怎么就不知道呢!其实很简单的……

1、首先引入头文件:#import <objc/runtime.h>

unsigned int count = 0;

Ivar *ivars = class_copyIvarList([UITextField class], &count);

    for (int i = 0; i<count; i++) {

         Ivar ivar = ivars[i];

        NSLog(@"UITextField--->%s------%s", ivar_getName(ivar),ivar_getTypeEncoding(ivar));

    }

打印结果:

UITextField--->_textStorage------@"_UICascadingTextStorage"

UITextField--->_borderStyle------q

UITextField--->_minimumFontSize------d

UITextField--->_delegate------@

UITextField--->_background------@"UIImage"

UITextField--->_disabledBackground------@"UIImage"

UITextField--->_clearButtonMode------q

UITextField--->_leftView------@"UIView"

UITextField--->_leftViewMode------q

UITextField--->_rightView------@"UIView"

UITextField--->_rightViewMode------q

UITextField--->_traits------@"UITextInputTraits"

UITextField--->_nonAtomTraits------@"UITextInputTraits"

UITextField--->_fullFontSize------d

UITextField--->_padding------{UIEdgeInsets="top"d"left"d"bottom"d"right"d}

UITextField--->_selectionRangeWhenNotEditing------{_NSRange="location"Q"length"Q}

UITextField--->_scrollXOffset------i

UITextField--->_scrollYOffset------i

UITextField--->_progress------f

UITextField--->_clearButton------@"UIButton"

UITextField--->_clearButtonOffset------{CGSize="width"d"height"d}

UITextField--->_leftViewOffset------{CGSize="width"d"height"d}

UITextField--->_rightViewOffset------{CGSize="width"d"height"d}

UITextField--->_backgroundView------@"UITextFieldBorderView"

UITextField--->_disabledBackgroundView------@"UITextFieldBorderView"

UITextField--->_systemBackgroundView------@"UITextFieldBackgroundView"

UITextField--->_floatingContentView------@"_UIFloatingContentView"

UITextField--->_contentBackdropView------@"UIVisualEffectView"

UITextField--->_fieldEditorBackgroundView------@"_UIDetachedFieldEditorBackgroundView"

UITextField--->_fieldEditorEffectView------@"UIVisualEffectView"

UITextField--->_displayLabel------@"UITextFieldLabel"

UITextField--->_placeholderLabel------@"UITextFieldLabel"

UITextField--->_suffixLabel------@"UITextFieldLabel"

UITextField--->_prefixLabel------@"UITextFieldLabel"

UITextField--->_iconView------@"UIImageView"

UITextField--->_label------@"UILabel"

UITextField--->_labelOffset------d

UITextField--->_interactionAssistant------@"UITextInteractionAssistant"

UITextField--->_selectGestureRecognizer------@"UITapGestureRecognizer"

UITextField--->_inputView------@"UIView"

UITextField--->_inputAccessoryView------@"UIView"

UITextField--->_systemInputViewController------@"UISystemInputViewController"

UITextField--->_atomBackgroundView------@"UITextFieldAtomBackgroundView"

UITextField--->_textFieldFlags------{?="verticallyCenterText"b1"isAnimating"b4"inactiveHasDimAppearance"b1"becomesFirstResponderOnClearButtonTap"b1"clearsPlaceholderOnBeginEditing"b1"adjustsFontSizeToFitWidth"b1"fieldEditorAttached"b1"canBecomeFirstResponder"b1"shouldSuppressShouldBeginEditing"b1"inResignFirstResponder"b1"undoDisabled"b1"explicitAlignment"b1"implementsCustomDrawing"b1"needsClearing"b1"suppressContentChangedNotification"b1"allowsEditingTextAttributes"b1"usesAttributedText"b1"backgroundViewState"b2"clearingBehavior"b2"overridePasscodeStyle"b1"shouldResignWithoutUpdate"b1"blurEnabled"b1"disableFocus"b1}

UITextField--->_deferringBecomeFirstResponder------B

UITextField--->_avoidBecomeFirstResponder------B

UITextField--->_setSelectionRangeAfterFieldEditorIsAttached------B

UITextField--->_animateNextHighlightChange------B

UITextField--->_baselineLayoutConstraint------@"NSLayoutConstraint"

UITextField--->_baselineLayoutLabel------@"_UIBaselineLayoutStrut"

2、现在我们可以根据这些打印出来的隐藏的属性来修改我们要改的东西了,比如这个输入框中placeholderLabel的字体颜色
   
   [_textField setValue:[UIColor blueColor] forKeyPath:@"_placeholderLabel.textColor"]; 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值