UIAlertView UITextField显示黑色边框

时间:2015-04-01 06:47:21

标签: ios objective-c uialertview

我正在使用textinput创建UIAlertView,但是我清除了背景并给出了边框颜色,显示出黑色边框。

UIAlertView *alerttorename=[[UIAlertView alloc]initWithTitle:@"Dropbox Export" message:@"Export As:" delegate:projectDetailsReference cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
            alerttorename.alertViewStyle = UIAlertViewStylePlainTextInput;
            [[alerttorename textFieldAtIndex:0] setText:[appDelegate.projectName stringByDeletingPathExtension]];
            UITextField *textField = [alerttorename textFieldAtIndex:0];
            [textField setBackgroundColor:[UIColor clearColor]];
            textField.borderStyle=UITextBorderStyleRoundedRect ;
            textField.layer.borderColor=[[UIColor lightGrayColor]CGColor];
            textField.layer.borderWidth = 0.1f;
            textField.layer.cornerRadius = 5;
            textField.clipsToBounds      = YES;

            alerttorename.tag=233;
            [alerttorename show];

2 个答案:

答案 0 :(得分:0)

参考此示例,UIAlertController:

UIAlertController *alertController = [UIAlertController
                alertControllerWithTitle:alertTitle
                                 message:alertMessage
                          preferredStyle:UIAlertControllerStyleAlert];

[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)
 {
       textField.placeholder = NSLocalizedString(@"LoginPlaceholder", @"Login");
 }];

[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)
 {
       textField.placeholder = NSLocalizedString(@"PasswordPlaceholder", @"Password");
       textField.secureTextEntry = YES;
 }];

可以在OK操作处理程序中检索文本字段的值:

UIAlertAction *okAction = [UIAlertAction
  actionWithTitle:NSLocalizedString(@"OK", @"OK action")
  style:UIAlertActionStyleDefault
  handler:^(UIAlertAction *action)
  {
    UITextField *login = alertController.textFields.firstObject;
    UITextField *password = alertController.textFields.lastObject;
  }];

有关UIAlertController的更多信息,请参阅此link

答案 1 :(得分:0)

使用此类别UIViewalertView中显示iOS > 7.0。在这里,您无需担心UIAlertViewUIAlertViewController

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

@interface UIView (AlertView)
+( void )showSimpleAlertWithTitle:( NSString * )title
                      message:( NSString * )message
            cancelButtonTitle:( NSString * )cancelButtonTitle;
@end

@interface UIView (AlertView)

+( void )showSimpleAlertWithTitle:( NSString * )title
                      message:( NSString * )message
            cancelButtonTitle:( NSString * )cancelButtonTitle
{
  if(SYSTEM_VERSION_LESS_THAN(@"8"))
  {
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle: title
                                                    message: message
                                                   delegate: nil
                                          cancelButtonTitle: cancelButtonTitle
                                          otherButtonTitles: nil];
      [alert show];
  }
  else
  {
      // nil titles break alert interface on iOS 8.0, so we'll be using empty strings
      UIAlertController *alert = [UIAlertController alertControllerWithTitle: title == nil ? @"": title
                                                                   message: message
                                                            preferredStyle: UIAlertControllerStyleAlert];

      UIAlertAction *defaultAction = [UIAlertAction actionWithTitle: cancelButtonTitle
                                                            style: UIAlertActionStyleDefault
                                                          handler: nil];

      [alert addAction: defaultAction];

      UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
      [rootViewController presentViewController: alert animated: YES completion: nil];
  }
}

@end

使用此类别:

 [UIView showSimpleAlertWithTitle:@"Title here" message:@"Message here" cancelButtonTitle:@"Ok"];