Program/iOS

iOS - TextField 자간 조정

핸디앤디 2011. 11. 10. 15:36
** 개인적 메모입니다. 태클 사절 **

CustomTextField.h


#import <Foundation/Foundation.h>



@interface CustomTextField : UITextField {

    

}


@end


CustomTextField.m


#import "CustomTextField.h"



@implementation CustomTextField


- (void) drawTextInRect:(CGRect)rect

{

    CGRect bounds = [self bounds];

    const char *result = [self.text UTF8String];

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSelectFont(context, "Arial"self.font.pointSizekCGEncodingMacRoman);

    CGContextSetTextDrawingMode(context, kCGTextFill);

    CGContextSetRGBFillColor(context, 1001);

    

    CGContextSetCharacterSpacing(context, 1); // <-----파라미터를 수정해주시면 됩니다.

    CGContextTranslateCTM(context, 0, bounds.size.height + 5);

    CGContextScaleCTM(context, 1, -1);

    CGContextShowTextAtPoint(context, 0, rect.size.height/2, result, strlen(result));

}


@end