自定义AlertView

- (void)viewDidLoad

{

    [super viewDidLoad];

    UIAlertView * myAlert = [[UIAlertView alloc] initWithTitle: @"信息提示:"

                                                       message: @"\n\n\n"

                                                      delegate: self

                                             cancelButtonTitle: @"Cancel"

                                             otherButtonTitles: @"OK", nil];

    

    textField1 = [[UITextField alloc] initWithFrame: CGRectMake(12.0f, 60.0f, 260.0f, 25.0f)];

    textField1.keyboardType = UIKeyboardTypeAlphabet;

    textField1.keyboardAppearance = UIKeyboardAppearanceAlert;

    textField1.autocapitalizationType  = UITextAutocapitalizationTypeWords;

    textField1.autocorrectionType = UITextAutocapitalizationTypeNone;

    textField1.placeholder = @"默认值 ";

    textField1.borderStyle = UITextBorderStyleRoundedRect;

    textField1.textAlignment = UITextAlignmentLeft;

    textField1.tag = 2;

    textField1.delegate = self;

    field.delegate = self;

    [myAlert addSubview: textField1];

    

    [myAlert show];

    [myAlert release];

    [textField1 release];

// Do any additional setup after loading the view, typically from a nib.

}

//点击return 键盘下去

-(BOOL)textFieldShouldReturn:(UITextField *)textField

{

    [textField1 resignFirstResponder];

    [field resignFirstResponder];

    return YES;

}

//点击屏幕 键盘下去

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch=[[event allTouches] anyObject];

    if (touch.tapCount >=1) {

        [textField1 resignFirstResponder];

        [field resignFirstResponder];

    }

}

你可能感兴趣的:(自定义AlertView)