Jul 2, 2013

IOS Xcode Create a modal window

Create  a modal window for IOS application in Xcode 

1. Create new view controller either programatically or using a nib file, design it the way you want your modal window to be.
2. Name it youtubeplayer (say).
3. Import its header file into the main view controller (obviously).
4. From the main view controller put the below code into any event. ( clicking of button, or table row selected etc.) 

youtubeplayer *yt = [[youtubeplayer alloc]  initWithNibName:@"youtubeplayer" bundle:[NSBundle mainBundle]];    yt.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;    yt.modalPresentationStyle = UIModalPresentationFormSheet;    [self presentViewController:yt animated:YES completion:^{        NSLog(@"this is calleed");    }];    CGRect r = CGRectMake(self.view.bounds.size.width/2 - 350,                          self.view.bounds.size.height/2 - 200,                          700, 400);    r = [self.view convertRect:r toView:yt.view.superview.superview];    yt.view.superview.frame = r;

Also now you will need a button on the modal window opened to close it.
simply create a button or what ever element you are comfortable with and put in the following code in it.

- (IBAction)closeModal:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}

that's it Now you are good to go.


If need any help You can ask in comments.

Happy Coding :)

No comments:

Post a Comment