프로그래밍/iOS
AlertView Login만들기
백룡화검
2012. 6. 15. 17:59
UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Username and password"
message:@"\n\n\n" // 중요!! 칸을 내려주는 역할을 합니다.
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Enter", nil];
textFieldName = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)];
[textFieldName setBackgroundColor:[UIColor whiteColor]];
[textFieldName setPlaceholder:@"username"];
[prompt addSubview:textFieldName];
textFieldPassword = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 25.0)];
[textFieldPassword setBackgroundColor:[UIColor whiteColor]];
[textFieldPassword setPlaceholder:@"password"];
[textFieldPassword setSecureTextEntry:YES];
[prompt addSubview:textFieldPassword];
// AlertView의 위치를 이동 시켜 줌.
// [prompt setTransform:CGAffineTransformMakeTranslation(0.0, 110.0)];
[prompt show];
[prompt release];
// textfield에 커서를 보내고 키보드를 표시 해 줌.
[textFieldName becomeFirstResponder];
In the .h file
1
2
| UITextField *textfieldName;
UITextField *textfieldPassword; |
In the .m file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// Clicked the Submit button
if (buttonIndex != [alertView cancelButtonIndex])
{
NSLog(@"Name: %@", textfieldName.text);
NSLog(@"Name: %@", textfieldPassword.text);
}
}
...
- (void) someMethod
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please Login" message:@""
delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Submit", nil];
[alert addTextFieldWithValue:@"" label:@"User Name"];
[alert addTextFieldWithValue:@"" label:@"Password"];
// Username
textfieldName = [alert textFieldAtIndex:0];
textfieldName.keyboardType = UIKeyboardTypeAlphabet;
textfieldName.keyboardAppearance = UIKeyboardAppearanceAlert;
textfieldName.autocorrectionType = UITextAutocorrectionTypeNo;
// Password
textfieldPassword = [alert textFieldAtIndex:1];
textfieldPassword.clearButtonMode = UITextFieldViewModeWhileEditing;
textfieldPassword.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
textfieldPassword.keyboardAppearance = UIKeyboardAppearanceAlert;
textfieldPassword.autocorrectionType = UITextAutocorrectionTypeNo;
textfieldPassword.secureTextEntry = YES;
[alert show];
}
|