UITextField align left margin and clear button


you can do it by overriding two methods:

- (CGRect)textRectForBounds:(CGRect)bounds;
- (CGRect)editingRectForBounds:(CGRect)bounds;
- (CGRect)clearButtonRectForBounds:(CGRect)bounds;
the first one to align the placeholder and the second one for the editable text, so here is the code following your first answer


@implementation MYTextField


- (CGRect)textRectForBounds:(CGRect)bounds {
    CGRect inset = CGRectMake(bounds.origin.x + 10, bounds.origin.y, bounds.size.width - 10, bounds.size.height);
    return inset;
}


- (CGRect)editingRectForBounds:(CGRect)bounds {
    CGRect inset = CGRectMake(bounds.origin.x + 10, bounds.origin.y, bounds.size.width - 10, bounds.size.height);
    return inset;
}



- (CGRect)clearButtonRectForBounds:(CGRect)bounds {
    CGRect inset = CGRectMake(bounds.origin.x + 113, bounds.origin.y, bounds.size.width - 10, bounds.size.height);
    return inset;
}