- Posted
- Filed under 01010101
UITextField 를 상속받는 서브클래스를 만들어야 합니다.
서브클래스를 만들어서, 아래 메소드를 override 하고,
[CODE]- (CGRect)textRectForBounds:(CGRect)bounds;
- (CGRect)editingRectForBounds:(CGRect)bounds;
[/CODE]
그리고, padding 값을 변경 할 수 있도록,
"paddingX" "paddingY" properties 를 추가합니다.
[CODE]//
// CSTextField.h
//
// Created by Cho, Young-Un on 11. 9. 17..
// Copyright 2011 cultstory.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface CSTextField : UITextField {
@private
NSInteger _paddingX;
NSInteger _paddingY;
}
@property (nonatomic, assign) NSInteger paddingX;
@property (nonatomic, assign) NSInteger paddingY;
@end[/CODE]
[CODE]//
// CSTextField.m
//
// Created by Cho, Young-Un on 11. 9. 17..
// Copyright 2011 cultstory.com. All rights reserved.
//
#import "CSTextField.h"
@implementation CSTextField
@synthesize paddingX=_paddingX, paddingY=_paddingY;
- (CGRect)textRectForBounds:(CGRect)bounds {
return CGRectMake(bounds.origin.x + _paddingX,
bounds.origin.y + _paddingY,
bounds.size.width - (_paddingX * 2),
bounds.size.height - (_paddingY * 2));
}
- (CGRect)editingRectForBounds:(CGRect)bounds {
return [self textRectForBounds:bounds];
}
@end[/CODE]
참고: http://stackoverflow.com/questions/3727068/set-padding-for-uitextfield-with-uitextborderstylenone