Created
August 27, 2015 15:23
-
-
Save dutran90/9a2dc844cf73f16277ba to your computer and use it in GitHub Desktop.
MyTextFiled padding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface MyTextField : UITextField | |
{ | |
BOOL isEnablePadding; | |
float paddingLeft; | |
float paddingRight; | |
float paddingTop; | |
float paddingBottom; | |
} | |
- (void)setPadding:(BOOL)enable top:(float)top right:(float)right bottom:(float)bottom left:(float)left; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "MyTextField.h" | |
@implementation MyTextField | |
- (void)setPadding:(BOOL)enable top:(float)top right:(float)right bottom:(float)bottom left:(float)left { | |
isEnablePadding = enable; | |
paddingTop = top; | |
paddingRight = right; | |
paddingBottom = bottom; | |
paddingLeft = left; | |
} | |
- (CGRect)textRectForBounds:(CGRect)bounds { | |
if (isEnablePadding) { | |
return CGRectMake(bounds.origin.x + paddingLeft, | |
bounds.origin.y + paddingTop, | |
bounds.size.width - paddingRight, bounds.size.height - paddingBottom); | |
} else { | |
return CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height); | |
} | |
} | |
- (CGRect)editingRectForBounds:(CGRect)bounds { | |
return [self textRectForBounds:bounds]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment