2014-12-05 23 views
7

Próbuję użyć UIActionController w ios, aby pokazać pole tekstowe, i chcę wiedzieć, jak zmienić kolor obramowania pola tekstowego.Jak zmienić kolor obramowania pola tekstowego UIAlertController

mojego kodu jest:

- (void)showChangePasswordAlertView 
{ 
    UIAlertController *actionVC = [UIAlertController alertControllerWithTitle:@"" 
                    message:@"Change your password." 
                  preferredStyle:UIAlertControllerStyleAlert]; 
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" 
               style:UIAlertActionStyleDefault 
               handler:^(UIAlertAction *action) { 
               }]; 
    [actionVC addAction:action]; 

    action = [UIAlertAction actionWithTitle:@"Cancel" 
             style:UIAlertActionStyleDefault 
            handler:^(UIAlertAction *action) { 
            }]; 
    [actionVC addAction:action]; 

    [actionVC addTextFieldWithConfigurationHandler:^(UITextField *textField) { 
     textField.placeholder = @"old password"; 
     textField.borderStyle = UITextBorderStyleNone; 
     textField.layer.borderColor = [UIColor redColor].CGColor; 
     textField.layer.borderWidth = 1.0 ; 
     textField.secureTextEntry = YES ; 
    }]; 

    [actionVC addTextFieldWithConfigurationHandler:^(UITextField *textField) { 
     textField.placeholder = @"new password"; 
     textField.borderStyle = UITextBorderStyleNone; 
     textField.secureTextEntry = YES ; 
    }]; 

    [actionVC addTextFieldWithConfigurationHandler:^(UITextField *textField) { 
     textField.placeholder = @"confirm new password"; 
     textField.borderStyle = UITextBorderStyleNone; 
     textField.secureTextEntry = YES ; 
    }]; 

    [self presentViewController:actionVC animated:YES completion:nil]; 
} 

ale wynik jest:

enter image description here

każdy organ wie jak to zrobić? Dzięki.

+1

Czy rozwiązałeś problem? –

Odpowiedz

0

To trochę hacky, ale na pewno działa (testowane na iOS 8.3):

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert" 
                   message:@"This is an alert." 
                 preferredStyle:UIAlertControllerStyleAlert]; 

[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { 

    textField.placeholder = @"This is my placeholder"; 
    [[textField superview] superview].backgroundColor = [UIColor redColor]; 

}]; 
+0

Ta odpowiedź nie działa dla mnie w wersji 9.x. – Hima

0

To hacky zbyt

później pokaż UIAletController:

viewController.present(alert, animated: true, completion: nil) 

Dodaj ten kod:

YOUR_ALERT_CONTROLLER.textFields.forEach { 
    if let views = $0.superview?.superview?.subviews { 
     for case let visualView as UIVisualEffectView in views { 
      visualView.contentView.subviews.first?.backgroundColor = CURRENT_COLOR 
     } 
     } 
    } 
Powiązane problemy