Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create PopOver Without Arrows and Centered in UIViewController

I am attempting to display a PopOver in the Center of the ipad in Landscape Orientation. I am able to do it now with the code below but it does not have the Properties that are associated with the "popOverViewController" that is linked up on storyboard. I want it to be a view on storyboard so that I am able to work on and edit it. As well as be able to change the size of it to be either 50% or 75% of the ipads full view and no arrow...

Please, anything will help. *Updated code....can now set size. But still not seeing the "popOverViewController" content.

self.popOverViewController = [[PopOverViewController alloc]init];
self.popOver = [[UIPopoverController alloc]
                            initWithContentViewController:self.popOverViewController];
CGSize size = CGSizeMake(400.0,300.0);
[self.popOver setPopoverContentSize:size];
CGRect rect = CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 1, 1);
[self.popOver presentPopoverFromRect:rect inView:self.view permittedArrowDirections:0 animated:YES];
like image 372
DTDev Avatar asked Nov 12 '22 10:11

DTDev


1 Answers

Just copy & Paste the below code

UIViewController *popovercontroller=[[UIViewController alloc] init];
UIView *popoverView=[[UIView alloc] initWithFrame:CGRectMake(312,390, 400, 344)];
popoverView.backgroundColor=[UIColor whiteColor];

popovercontroller.contentSizeForViewInPopover=CGSizeMake(400, 300);



UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 400, 0)];
[pickerView setTintColor:[UIColor blackColor]];
[pickerView addTarget:self action:@selector(dueDateChanged:) forControlEvents:UIControlEventValueChanged];

pickerView.datePickerMode = UIDatePickerModeDate;
pickerView.hidden = NO;
NSString *bs ; //= [NSString alloc];
//    //NSDate *newDate = [NSData alloc];
bs =  CurrentSelectedDate;
if (bs.length >= 1) {
    NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init] ;
    //        //[dateFormatter setDateStyle:NSDateFormatterLongStyle];
    //        [dateFormatter setTimeStyle:NSDateFormatterNoStyle];
    [dateFormatter setDateFormat:@"dd-MMM-yyyy"];
    // NSDate *myDate = [dateFormatter dateFromString: txtText.text];
    pickerView.date = [dateFormatter dateFromString: CurrentSelectedDate];

}
else
{
    pickerView.date = [NSDate date];
}
[popoverView addSubview:pickerView];



// pickerView.date = [dateFormatter dateFromString:txtText.text];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 400, 44)];
pickerToolbar.barStyle = UIBarStyleDefault;
pickerToolbar.barTintColor=[UIColor colorWithRed:150.0f/255.0f green:91.0f/255.0f blue:129.0f/255.0f alpha:1.0f];

[pickerToolbar sizeToFit];
self.navigationController.toolbar.barTintColor = [UIColor colorWithRed:150.0f/255.0f green:91.0f/255.0f blue:129.0f/255.0f alpha:1.0f];
NSMutableArray *barItems = [[NSMutableArray alloc] init];

UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
[barItems addObject:flexSpace];

UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
doneBtn.tintColor=[UIColor whiteColor];
[barItems addObject:doneBtn];

UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
 cancelBtn.tintColor=[UIColor whiteColor];
[barItems addObject:cancelBtn];

[pickerToolbar setItems:barItems animated:YES];


[popoverView addSubview:pickerToolbar];
popovercontroller.view=popoverView;

pickerViewPopup = [[UIPopoverController alloc] initWithContentViewController:popovercontroller];

[pickerViewPopup presentPopoverFromRect:CGRectMake(312, 212, 400, 344) inView:self.view permittedArrowDirections:0 animated:YES];
like image 162
Baljeet Singh Avatar answered Nov 15 '22 05:11

Baljeet Singh