- Xcode 를 이용하여 텍스트필드를 만들고, 바탕화면을 눌렸을때 키패드가 사라지도록 만들어 보자.
- Label 하나 Text Field 하나 Button(속성 Custom) 하나를 만들고 Button은 화면을 가득 체워 놓자.
Button를 이용해서, 키패드를 밑으로 내릴 동작을 넣을 것이다.
- 화면디자인
Button은 View 제일 위에 두어야 한다. 그리고 ViewController.h 에 인터페이스를 등록해 하자.
- Text Field 만들기 순서
1. Xcode 실행
2. Single View Application
3. Project Name : “InputTest”
4. storyboard에 Text Field와 Label 위치
5. Assistant Editor로 Text Field와 Label 드래그
6. “myLabel”과 “myTextField” 입력
7. Button을 Assistant Editor로 드래그 Connection을 Action으로 변경 “inputText” 입력
8. ViewController.m 파일에 입력
-(IBAction)inputText{
myLabel.text = myTextField.text;
//[myTextField resignFirstResponder];
}
9. Control 키를 누를 상태에서 Text Field 클릭
10. Did End On Exit 오른쪽에 있는 동그라미를 뷰의 빈 영역에 드래그
11. inputText 선택
12. Command+R
- ViewController.m 소스코드
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize myLabel;
@synthesize myTextField;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setMyLabel:nil];
[self setMyTextField:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
- (IBAction)inputText:(id)sender {
myLabel.text = myTextField.text;
[myTextField resignFirstResponder];
}
@end
- 실행화면
'C/Objective C > ios' 카테고리의 다른 글
아이폰 Switch 만들기 예제 따라하기. (0) | 2012.07.15 |
---|---|
아이폰 Text View 만들기 예제 따라하기 (0) | 2012.07.15 |
Xcode 4 Keyboard Shortcuts(Xcode 4 키보드 단축키) (0) | 2012.07.11 |
iOSApplicationLifeCycle (0) | 2012.07.11 |
아이폰 Button 만들기 예제 따라하기 (0) | 2012.07.11 |