QMUITextField

@interface QMUITextField : UITextField

支持的特性包括:

  1. 自定义 placeholderColor。
  2. 自定义 UITextField 的文字 padding。
  3. 支持限制输入的文字的长度。
  4. 修复 iOS 10 之后 UITextField 输入中文超过文本框宽度后再删除,文字往下掉的 bug。
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, weak) id<QMUITextFieldDelegate> delegate

    Swift

    weak var delegate: QMUITextFieldDelegate! { get set }
  • 修改 placeholder 的颜色,默认是 UIColorPlaceholder。

    Declaration

    Objective-C

    @property (nonatomic, strong) UIColor *placeholderColor;

    Swift

    var placeholderColor: UIColor! { get set }
  • 文字在输入框内的 padding。如果出现 clearButton,则 textInsets.right 会控制 clearButton 的右边距

    默认为 TextFieldTextInsets

    Declaration

    Objective-C

    @property (nonatomic) UIEdgeInsets textInsets;

    Swift

    var textInsets: UIEdgeInsets { get set }
  • clearButton 在默认位置上的偏移

    Declaration

    Objective-C

    @property (nonatomic) UIOffset clearButtonPositionAdjustment;

    Swift

    var clearButtonPositionAdjustment: UIOffset { get set }
  • 当通过 setText:setAttributedText:等方式修改文字时,是否应该自动触发 UIControlEventEditingChanged 事件及 UITextFieldTextDidChangeNotification 通知。

    默认为YES(注意系统的 UITextField 对这种行为默认是 NO)

    Declaration

    Objective-C

    @property (nonatomic) BOOL shouldResponseToProgrammaticallyTextChanges;

    Swift

    var shouldResponseToProgrammaticallyTextChanges: Bool { get set }
  • 显示允许输入的最大文字长度,默认为 NSUIntegerMax,也即不限制长度。

    Declaration

    Objective-C

    @property (nonatomic) NSUInteger maximumTextLength;

    Swift

    var maximumTextLength: UInt { get set }
  • 在使用 maximumTextLength 功能的时候,是否应该把文字长度按照 [NSString (QMUI) qmui_lengthWhenCountingNonASCIICharacterAsTwo] 的方法来计算。 默认为 NO。

    Declaration

    Objective-C

    @property (nonatomic) BOOL shouldCountingNonASCIICharacterAsTwo;

    Swift

    var shouldCountingNonASCIICharacterAsTwo: Bool { get set }