'iphone'에 해당되는 글 1건

  1. 2011.02.15 [UITextField] - right button, font size, text 정렬, delegate 설정

UITextField 생성
UITextField *textField = [[UITextField alloc] initWithFrame: CGRectMake(5, 5, 200, 20)];

Font size 설정
textField.font = [UIFont systemFontOfSize: 12.0f];

Border 설정
textField.borderStyle = UITextBorderStyleLine;

Text 삽입
textField.text = @"안녕하세요";

Right button 삽입
UIButton *button = [[UIButton alloc] initWithFrame: CGRectMake(0, 0, 50, 15)];
[button setTitle: @"버튼" forState: UIControlStateNormal];
[button setTitleColor: [UIColor redColor] forState: UIControlStateNormal];
[button setBackgroundColor: [UIColor blueColor]];
[button addTarget: self action: @seletor(excute) forControlEvents: UIControlEventTouchUpInside];

textField.rightView = button;
textField.rightViewMode = UITextFieldViewModeAlways;

Text 정렬
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.textAlignment = UITextAlignmentCenter;

UITextField 비활성화
textField.enabled = NO;

Delegate 설정
CustomTextFieldDelegate *pDelegate = [[CustomTextFieldDelegate alloc] init];
textField.delegate = pDelegate;


CustomTextFieldDelegate.h
@interface CustomTextFieldDelegate : NSObject <UITextFieldDelegate> {
}
@end

CustomTextFieldDelegate.m
-(BOOL) textFieldShouldBeginEditing: (UITextField *) textField {
    return NO;
}

콤보박스를 만들때 text를 사용자가 수정하지 못하게 만들고 싶을 때 사용하자.

Posted by 짱가쟁이
이전버튼 1 이전버튼