UITextField的左右图片,内容位置调整,解决输入框输入时上下抖动

写输入界面时UITextField左边一般都会插入一个图片,以前直接约束一个UIImageView上去,今天看到了苹果原来已经提供了属性。

@property(nullable, nonatomic,strong) UIView *leftView;//左视图

 

@property(nonatomic) UITextFieldViewMode leftViewMode; //设置时机UITextFieldViewModeAlways即可

@property(nullable, nonatomic,strong) UIView *rightView//右视图
@property(nonatomic) UITextFieldViewMode rightViewMode;//设置时机UITextFieldViewModeAlways即可

 

 

//可以重写以下方法来调整相应位置

 

- (CGRect)borderRectForBounds:(CGRect)bounds;//边框
- (CGRect)textRectForBounds:(CGRect)bounds;//文本输入完成时
- (CGRect)placeholderRectForBounds:(CGRect)bounds;//占位符
- (CGRect)editingRectForBounds:(CGRect)bounds;//文本输入时
- (CGRect)clearButtonRectForBounds:(CGRect)bounds;//清除按钮
- (CGRect)leftViewRectForBounds:(CGRect)bounds;//左视图

 

- (CGRect)rightViewRectForBounds:(CGRect)bounds; //右试图

 

 //解决输入时向下抖动的情况

- (CGRect)editingRectForBounds:(CGRect)bounds {
return CGRectInset( bounds , 1 , 0 );
}

 

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值