iOS 13 ,UITextField rightView leftView 错位显示,解决办法

先上图来看看:

正确的

Simulator Screen Shot - iPhone 11 Pro Max - 2019-09-29 at 17.35.59.png

错误的

Simulator Screen Shot - iPhone 11 Pro Max - 2019-09-29 at 17.36.52.png

解决办法

解决输入框位置显示不对

- (CGRect)rightViewRectForBounds:(CGRect)bounds {
    CGRect rightViewRect = [super rightViewRectForBounds:bounds];

    if (@available(iOS 13.0, *)) {
        
        CGFloat left = self.frame.size.width - self.rightView.frame.size.width;
        CGFloat top = round((self.frame.size.height - self.rightView.frame.size.height)/2.0);
        rightViewRect = CGRectMake( left, top, self.rightView.frame.size.width , self.rightView.frame.size.height);
    } else {
        
    }

    return rightViewRect;
}


- (CGRect)leftViewRectForBounds:(CGRect)bounds {
    CGRect leftViewRect = [super leftViewRectForBounds:bounds];

    if (@available(iOS 13.0, *)) {
        CGFloat top = round((self.frame.size.height - self.leftView.frame.size.height)/2.0);

        leftViewRect = CGRectMake(0, top, self.leftView.frame.size.width, self.leftView.height);

    } else {
        
    }
    return leftViewRect;
}

喜欢的话,给个星星哟,如果没有解决你的问题,也可以留言,我看到了,会想想解决办法的

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容