2011. 2. 15. 16:43
UITextField 생성
Font size 설정
Border 설정
Text 삽입
Right button 삽입
Text 정렬
UITextField 비활성화
Delegate 설정
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;
[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;
textField.textAlignment = UITextAlignmentCenter;
UITextField 비활성화
textField.enabled = NO;
Delegate 설정
CustomTextFieldDelegate *pDelegate = [[CustomTextFieldDelegate alloc] init];
textField.delegate = pDelegate;
textField.delegate = pDelegate;
CustomTextFieldDelegate.h
CustomTextFieldDelegate.m
콤보박스를 만들때 text를 사용자가 수정하지 못하게 만들고 싶을 때 사용하자.
@interface CustomTextFieldDelegate : NSObject <UITextFieldDelegate> {
}
@end
}
@end
CustomTextFieldDelegate.m
-(BOOL) textFieldShouldBeginEditing: (UITextField *) textField {
return NO;
}
return NO;
}
콤보박스를 만들때 text를 사용자가 수정하지 못하게 만들고 싶을 때 사용하자.
'아이폰_Object-C' 카테고리의 다른 글
[Objective-C] - 다형성, 동적타이핑, 동적바인딩 (0) | 2011.02.08 |
---|