imbear

UIAlertView Changes

Jul 8th, 2013
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void) showLoginPrompt
  2. {
  3.     @autoreleasepool {
  4.        
  5.         loginAlertView = [UIAlertView alloc];
  6.        
  7.         if ([loginAlertView respondsToSelector:@selector(setAlertViewStyle:)]) {
  8.             [loginAlertView initWithTitle:WD_MSG_LOGIN message:WD_MSG_LOGINPROMPT delegate:self cancelButtonTitle:WD_MSG_CANCEL otherButtonTitles:WD_MSG_CONNECT,nil];
  9.             loginAlertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
  10.             NSString *name;// = TMD_MSG_LOGINNAME;
  11.             NSString *code;// = TMD_MSG_LOGINCODE;
  12. #if (AW_WIVIA)
  13.             name = WD_MSG_NAME;
  14.             code = WD_MSG_CODE_WIVIA;
  15. #else
  16.             name = WD_MSG_NAME;
  17.             code = WD_MSG_CODE;
  18. #endif
  19.             UITextField *tfName = [loginAlertView textFieldAtIndex:0];
  20.             tfName.placeholder = name;
  21.             tfName.returnKeyType = UIReturnKeyNext;
  22.             tfName.autocorrectionType = UITextAutocorrectionTypeNo;
  23.             tfName.autocapitalizationType = UITextAutocapitalizationTypeNone;
  24.             tfName.delegate = self;
  25.             tfName.text = [self readLoginName];
  26.            
  27.             UITextField *tfCode = [loginAlertView textFieldAtIndex:1];
  28.             tfCode.placeholder = code;
  29.             tfCode.returnKeyType = UIReturnKeyGo;
  30.             tfCode.keyboardType = UIKeyboardTypeNumberPad;
  31.             tfCode.autocorrectionType = UITextAutocorrectionTypeNo;
  32.             tfCode.autocapitalizationType = UITextAutocapitalizationTypeNone;
  33.             tfCode.delegate = self;
  34.             [tfCode becomeFirstResponder];
  35.         } else {
  36.             [loginAlertView initWithTitle:WD_MSG_LOGIN message:@"\n\n\n" delegate:self cancelButtonTitle:WD_MSG_CANCEL otherButtonTitles:WD_MSG_CONNECT,nil];
  37.         }
  38.        
  39.        
  40.         [loginAlertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
  41.         [loginAlertView release];
  42.     }
  43. }
  44.  
  45. - (void)willPresentAlertView:(UIAlertView *)alertView
  46. {
  47.     if( alertView==loginAlertView )
  48.     {
  49.         if ([alertView respondsToSelector:@selector(setAlertViewStyle:)]) {
  50.             ;//Do nothing.
  51.         } else {
  52.        
  53.             CGRect frame = alertView.frame;
  54.             NSString *name;// = TMD_MSG_LOGINNAME;
  55.             NSString *code;// = TMD_MSG_LOGINCODE;
  56. #if (AW_WIVIA)
  57.             name = WD_MSG_NAME;
  58.             code = WD_MSG_CODE_WIVIA;
  59. #else
  60.             name = WD_MSG_NAME;
  61.             code = WD_MSG_CODE;
  62. #endif
  63.            
  64.            
  65.             int gap = 12;
  66.             int labelGap = 4;
  67.            
  68.             int availableLength = frame.size.width - gap * 2;
  69.             CGSize sizeName, sizeCode;
  70.             sizeName = [name sizeWithFont:[UIFont systemFontOfSize:17]];
  71.             sizeCode = [code sizeWithFont:[UIFont systemFontOfSize:17]];
  72.             int nameLength = sizeName.width;
  73.             int codeLength = sizeCode.width;
  74.            
  75.             int adjustLength = MAX(nameLength, codeLength) ;
  76.            
  77.             float maxLabelLength = availableLength / 3.0;
  78.            
  79.             int labelLength = MIN(maxLabelLength, adjustLength);
  80.            
  81.             int textFieldLength = availableLength - labelLength - labelGap;
  82.            
  83.             int labelHeight = 28;
  84.            
  85.             int labelYOffset = 40;
  86.            
  87.            
  88.             UILabel *lbName = [[UILabel alloc] initWithFrame:CGRectMake(gap, labelYOffset, labelLength, labelHeight)];
  89.             lbName.text = name;
  90.             lbName.backgroundColor = [UIColor clearColor];
  91.             lbName.textColor = [UIColor whiteColor];
  92.             lbName.textAlignment = NSTextAlignmentRight;
  93.             lbName.adjustsFontSizeToFitWidth = YES;
  94.            
  95.             UILabel *lbCode = [[UILabel alloc] initWithFrame:CGRectMake(gap, labelYOffset + labelGap + labelHeight, labelLength, labelHeight)];
  96.             lbCode.text = code;
  97.             lbCode.backgroundColor = [UIColor clearColor];
  98.             lbCode.textColor = [UIColor whiteColor];
  99.             lbCode.textAlignment = NSTextAlignmentRight;
  100.             lbCode.adjustsFontSizeToFitWidth = YES;
  101.            
  102.             UITextField *tfName = [[UITextField alloc] initWithFrame:CGRectMake(gap + labelLength + labelGap, labelYOffset, textFieldLength, labelHeight)];
  103.             tfName.placeholder = name;
  104.             tfName.borderStyle=UITextBorderStyleRoundedRect;
  105.             tfName.returnKeyType = UIReturnKeyNext;
  106.             tfName.autocorrectionType = UITextAutocorrectionTypeNo;
  107.             tfName.autocapitalizationType = UITextAutocapitalizationTypeNone;
  108.             tfName.delegate = self;
  109.             tfName.text = [self readLoginName];
  110.             accountName = tfName ;
  111.             //      tfName.tag = TMD_TAG_RECEIVER_LOGINNAME;
  112.            
  113.             UITextField *tfCode = [[UITextField alloc] initWithFrame:CGRectMake(gap + labelLength + labelGap, labelYOffset + labelGap + labelHeight, textFieldLength, labelHeight)];
  114.             tfCode.placeholder = code;
  115.             tfCode.borderStyle=UITextBorderStyleRoundedRect;
  116.             tfCode.returnKeyType = UIReturnKeyGo;
  117.             tfCode.keyboardType = UIKeyboardTypeNumberPad;
  118.             tfCode.autocorrectionType = UITextAutocorrectionTypeNo;
  119.             tfCode.autocapitalizationType = UITextAutocapitalizationTypeNone;
  120.             tfCode.delegate = self;
  121.             //      tfCode.tag = TMD_TAG_RECEIVER_LOGINCODE;
  122.             accountPass = tfCode;
  123.             [tfCode becomeFirstResponder];
  124.            
  125.            
  126.             [alertView addSubview:lbName];
  127.             [alertView addSubview:lbCode];
  128.             [alertView addSubview:tfName];
  129.             [alertView addSubview:tfCode];
  130.         }
  131.        
  132.     }
  133. }
  134.  
  135. - (void)didPresentAlertView:(UIAlertView *)alertView {
  136.     if( alertView==loginAlertView )
  137.     {
  138.         [self resignFirstResponder];
  139.         if ([alertView respondsToSelector:@selector(setAlertViewStyle:)]) {
  140.             NSLog(@"%s, will set first responder, %@", __func__, [alertView subviews]);
  141.             [[alertView textFieldAtIndex:0] resignFirstResponder];
  142.             [[alertView textFieldAtIndex:1] becomeFirstResponder];
  143.             accountName = [alertView textFieldAtIndex:0];
  144.             accountPass = [alertView textFieldAtIndex:1];
  145.             accountName.delegate = self;
  146.             accountPass.delegate = self;
  147.             [accountPass becomeFirstResponder];
  148.         } else {
  149.             [accountPass performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.05];
  150.         }
  151.     }
  152. };
Advertisement
Add Comment
Please, Sign In to add comment