views:

47

answers:

1

I want to display an alert view with a search bar option on it.How can i create a search bar in a alert view.Please help me out.Any sample codes would me more helpful.

Thanks

A: 

I have created a search bar and and added the text box as its subview.

UIAlertView * myAlertView = [[UIAlertView alloc] initWithTitle:@"         " message:@"         " delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
        UISearchBar *myTextField = [[UISearchBar alloc] initWithFrame:CGRectMake(30.0, 35.0, 180.0, 35.0)];
        UIButton *searchbtn = [[UIButton alloc] initWithFrame:CGRectMake(230.0, 35.0, 40.0, 35.0)];
        [myTextField setBackgroundColor:[UIColor whiteColor]];
        [myAlertView setBackgroundColor:[UIColor grayColor]];
        [searchbtn setBackgroundColor:[UIColor grayColor]];
        [myAlertView addSubview:myTextField];
        [myAlertView addSubview:searchbtn];

If there is any other better way please help me out.

Warrior