Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void) showLoginPrompt
- {
- @autoreleasepool {
- loginAlertView = [UIAlertView alloc];
- if ([loginAlertView respondsToSelector:@selector(setAlertViewStyle:)]) {
- [loginAlertView initWithTitle:WD_MSG_LOGIN message:WD_MSG_LOGINPROMPT delegate:self cancelButtonTitle:WD_MSG_CANCEL otherButtonTitles:WD_MSG_CONNECT,nil];
- loginAlertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
- NSString *name;// = TMD_MSG_LOGINNAME;
- NSString *code;// = TMD_MSG_LOGINCODE;
- #if (AW_WIVIA)
- name = WD_MSG_NAME;
- code = WD_MSG_CODE_WIVIA;
- #else
- name = WD_MSG_NAME;
- code = WD_MSG_CODE;
- #endif
- UITextField *tfName = [loginAlertView textFieldAtIndex:0];
- tfName.placeholder = name;
- tfName.returnKeyType = UIReturnKeyNext;
- tfName.autocorrectionType = UITextAutocorrectionTypeNo;
- tfName.autocapitalizationType = UITextAutocapitalizationTypeNone;
- tfName.delegate = self;
- tfName.text = [self readLoginName];
- UITextField *tfCode = [loginAlertView textFieldAtIndex:1];
- tfCode.placeholder = code;
- tfCode.returnKeyType = UIReturnKeyGo;
- tfCode.keyboardType = UIKeyboardTypeNumberPad;
- tfCode.autocorrectionType = UITextAutocorrectionTypeNo;
- tfCode.autocapitalizationType = UITextAutocapitalizationTypeNone;
- tfCode.delegate = self;
- [tfCode becomeFirstResponder];
- } else {
- [loginAlertView initWithTitle:WD_MSG_LOGIN message:@"\n\n\n" delegate:self cancelButtonTitle:WD_MSG_CANCEL otherButtonTitles:WD_MSG_CONNECT,nil];
- }
- [loginAlertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
- [loginAlertView release];
- }
- }
- - (void)willPresentAlertView:(UIAlertView *)alertView
- {
- if( alertView==loginAlertView )
- {
- if ([alertView respondsToSelector:@selector(setAlertViewStyle:)]) {
- ;//Do nothing.
- } else {
- CGRect frame = alertView.frame;
- NSString *name;// = TMD_MSG_LOGINNAME;
- NSString *code;// = TMD_MSG_LOGINCODE;
- #if (AW_WIVIA)
- name = WD_MSG_NAME;
- code = WD_MSG_CODE_WIVIA;
- #else
- name = WD_MSG_NAME;
- code = WD_MSG_CODE;
- #endif
- int gap = 12;
- int labelGap = 4;
- int availableLength = frame.size.width - gap * 2;
- CGSize sizeName, sizeCode;
- sizeName = [name sizeWithFont:[UIFont systemFontOfSize:17]];
- sizeCode = [code sizeWithFont:[UIFont systemFontOfSize:17]];
- int nameLength = sizeName.width;
- int codeLength = sizeCode.width;
- int adjustLength = MAX(nameLength, codeLength) ;
- float maxLabelLength = availableLength / 3.0;
- int labelLength = MIN(maxLabelLength, adjustLength);
- int textFieldLength = availableLength - labelLength - labelGap;
- int labelHeight = 28;
- int labelYOffset = 40;
- UILabel *lbName = [[UILabel alloc] initWithFrame:CGRectMake(gap, labelYOffset, labelLength, labelHeight)];
- lbName.text = name;
- lbName.backgroundColor = [UIColor clearColor];
- lbName.textColor = [UIColor whiteColor];
- lbName.textAlignment = NSTextAlignmentRight;
- lbName.adjustsFontSizeToFitWidth = YES;
- UILabel *lbCode = [[UILabel alloc] initWithFrame:CGRectMake(gap, labelYOffset + labelGap + labelHeight, labelLength, labelHeight)];
- lbCode.text = code;
- lbCode.backgroundColor = [UIColor clearColor];
- lbCode.textColor = [UIColor whiteColor];
- lbCode.textAlignment = NSTextAlignmentRight;
- lbCode.adjustsFontSizeToFitWidth = YES;
- UITextField *tfName = [[UITextField alloc] initWithFrame:CGRectMake(gap + labelLength + labelGap, labelYOffset, textFieldLength, labelHeight)];
- tfName.placeholder = name;
- tfName.borderStyle=UITextBorderStyleRoundedRect;
- tfName.returnKeyType = UIReturnKeyNext;
- tfName.autocorrectionType = UITextAutocorrectionTypeNo;
- tfName.autocapitalizationType = UITextAutocapitalizationTypeNone;
- tfName.delegate = self;
- tfName.text = [self readLoginName];
- accountName = tfName ;
- // tfName.tag = TMD_TAG_RECEIVER_LOGINNAME;
- UITextField *tfCode = [[UITextField alloc] initWithFrame:CGRectMake(gap + labelLength + labelGap, labelYOffset + labelGap + labelHeight, textFieldLength, labelHeight)];
- tfCode.placeholder = code;
- tfCode.borderStyle=UITextBorderStyleRoundedRect;
- tfCode.returnKeyType = UIReturnKeyGo;
- tfCode.keyboardType = UIKeyboardTypeNumberPad;
- tfCode.autocorrectionType = UITextAutocorrectionTypeNo;
- tfCode.autocapitalizationType = UITextAutocapitalizationTypeNone;
- tfCode.delegate = self;
- // tfCode.tag = TMD_TAG_RECEIVER_LOGINCODE;
- accountPass = tfCode;
- [tfCode becomeFirstResponder];
- [alertView addSubview:lbName];
- [alertView addSubview:lbCode];
- [alertView addSubview:tfName];
- [alertView addSubview:tfCode];
- }
- }
- }
- - (void)didPresentAlertView:(UIAlertView *)alertView {
- if( alertView==loginAlertView )
- {
- [self resignFirstResponder];
- if ([alertView respondsToSelector:@selector(setAlertViewStyle:)]) {
- NSLog(@"%s, will set first responder, %@", __func__, [alertView subviews]);
- [[alertView textFieldAtIndex:0] resignFirstResponder];
- [[alertView textFieldAtIndex:1] becomeFirstResponder];
- accountName = [alertView textFieldAtIndex:0];
- accountPass = [alertView textFieldAtIndex:1];
- accountName.delegate = self;
- accountPass.delegate = self;
- [accountPass becomeFirstResponder];
- } else {
- [accountPass performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.05];
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment