Skip to content

Commit

Permalink
refactor: set textfield defalut clear button image
Browse files Browse the repository at this point in the history
  • Loading branch information
passerbyloo committed May 21, 2019
1 parent f46ab49 commit d8a518e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions QMUIKit/UIKitExtensions/UITextField+QMUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/// 输入框右边的 clearButton,在 UITextField 初始化后就存在
@property(nullable, nonatomic, weak, readonly) UIButton *qmui_clearButton;

/// 自定义 clearButton 的图片,注意如果设置过则无法再恢复到系统默认的图片
@property(nonnull, nonatomic, strong) UIImage *qmui_clearButtonImage UI_APPEARANCE_SELECTOR;
/// 自定义 clearButton 的图片,设置成nil,恢复到系统默认的图片
@property(nullable, nonatomic, strong) UIImage *qmui_clearButtonImage UI_APPEARANCE_SELECTOR;

@end
6 changes: 2 additions & 4 deletions QMUIKit/UIKitExtensions/UITextField+QMUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ - (UIButton *)qmui_clearButton {

static char kAssociatedObjectKey_clearButtonImage;
- (void)setQmui_clearButtonImage:(UIImage *)qmui_clearButtonImage {
if (qmui_clearButtonImage) {
objc_setAssociatedObject(self, &kAssociatedObjectKey_clearButtonImage, qmui_clearButtonImage, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self.qmui_clearButton setImage:qmui_clearButtonImage forState:UIControlStateNormal];
}
objc_setAssociatedObject(self, &kAssociatedObjectKey_clearButtonImage, qmui_clearButtonImage, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self.qmui_clearButton setImage:qmui_clearButtonImage forState:UIControlStateNormal];
}

- (UIImage *)qmui_clearButtonImage {
Expand Down

0 comments on commit d8a518e

Please sign in to comment.