如何在UITextField的左侧显示清除按钮?

Aru*_*i R 7 uitextfield ios

我正在用阿拉伯语开发一个应用程序,我有UITextField和textAlignment权限.现在我想在左侧显示textField的清除按钮.是否可以在不添加自定义按钮的情况下执行此操作?

当前位置

清除按钮位置

所期望的职位

清除按钮位置

use*_*rar 8

使用以下类别,并确保您的文本对齐应正确:)

@interface UICrossButtonTextField:UITextField
- (CGRect)clearButtonRectForBounds:(CGRect)bounds;
@end

@implementation UICrossButtonTextField
- (CGRect)clearButtonRectForBounds:(CGRect)bounds {
    CGRect originalRect = [super clearButtonRectForBounds:bounds];
    return CGRectOffset(originalRect, -originalRect.origin.x+5, 0); }


- (CGRect)editingRectForBounds:(CGRect)bounds {
    CGRect originalRect = [super clearButtonRectForBounds:bounds];
    bounds = CGRectMake(originalRect.size.width, bounds.origin.y, bounds.size.width-originalRect.size.width, bounds.size.height);
    return CGRectInset(bounds, 13, 3);
}

@end
Run Code Online (Sandbox Code Playgroud)