How to display clear button in left side of UITextField?

ios, uitextfield

Solution

Use below category and make sure your text alignment should be right :)

@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

Problem

I'm developing an app in Arabic language and I have UITextField with textAlignment right. Now I want to show the clear button of the textField in left side. Is it possible to do this without adding a custom button? Current position Desired position

Original source