Do Not Think!!!

최근 사진

2011/12 시즌 2012년 2월 18-19일 용평리조트
2011/12 시즌 2012년 1월 27-28일 휘닉스파크
사무실 이사
2011/12시즌 2011년 12월 17일 휘닉스파크
2011/12시즌 2011년 12월 10일 휘닉스파크
2011/12시즌 2011년 12월 4일 휘닉스파크
2011/12시즌 2011년 11월 26일 휘닉스파크
2011년 8월 뉴질랜드 여행
2011년 5월 4일 ~ 7일 홍콩 워크샵 사람
2011년 5월 4일 ~ 7일 홍콩 워크샵 넷 째날

최근 트랙백

Total226673
Today2
Yesterday103
2011/09/17 12:55

[iOS] UITextField padding 적용하기 by 조영운

UITextField 에서는 기본으로 패딩을 적용할 수 없기 때문에
UITextField 를 상속받는 서브클래스를 만들어야 합니다.


서브클래스를 만들어서, 아래 메소드를 override 하고,
- (CGRect)textRectForBounds:(CGRect)bounds;
- (CGRect)editingRectForBounds:(CGRect)bounds;

그리고, padding 값을 변경 할 수 있도록,
"paddingX" "paddingY" properties 를 추가합니다.





//
// 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





//
// 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




참고: http://stackoverflow.com/questions/3727068/set-padding-for-uitextfield-with-uitextborderstylenone
크리에이티브 커먼즈 라이센스
Creative Commons License

Trackback Address :: http://dont.pe.kr/tt/trackback/383

Name

Password

Homepage

Secret

PREV 1 ... 17 18 19 20 21 22 23 24 25 ... 360 NEXT