I want to show a popup with a calendar when the user presses a button. I have seen lots of popups but they don't include the arrow from the button pressed. I want something similar to the image below. I have done a calendar and I don't know how to insert it into a popover. Can someone give me a trick?
I know how to make a popover with a tableview but no with an other viewcontroller.
Thanks!!
I have solved my problem. I'm going to explain it step by step:
1- First of all I have created a popover 2- Then I have include a calendar to my project 3- Then I have add the calendar view into the popover
Here's the code:
- (IBAction)startPressed:(id)sender {
UIButton * popoverButton = (UIButton*) sender;
CKCalendarView *calendar = [[CKCalendarView alloc] initWithStartDay:startMonday];
self.calendar = calendar;
calendar.delegate = self;
self.dateFormatter = [[NSDateFormatter alloc] init];
[self.dateFormatter setDateFormat:@"dd/MM/yyyy"];
self.minimumDate = [self.dateFormatter dateFromString:@"20/09/2012"];
self.disabledDates = @[
[self.dateFormatter dateFromString:@"05/01/2013"],
[self.dateFormatter dateFromString:@"06/01/2013"],
[self.dateFormatter dateFromString:@"07/01/2013"]
];
calendar.onlyShowCurrentMonth = NO;
calendar.adaptHeightToNumberOfWeeksInMonth = YES;
calendar.tag = 0;
calendar.frame = CGRectMake(10, 10, 300, 320);
self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(calendar.frame) + 4, self.view.bounds.size.width, 24)];
[self.view addSubview:self.dateLabel];
self.view.backgroundColor = [UIColor whiteColor];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(localeDidChange) name:NSCurrentLocaleDidChangeNotification object:nil];
popoverContent = [[UIViewController alloc]
init];
UIView* popoverView = [[UIView alloc]
initWithFrame:CGRectMake(0, 0, 300, 220)];
popoverView.backgroundColor = [UIColor whiteColor];
popoverContent.view = calendar;
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover =
CGSizeMake(300, 220);
//create a popover controller
self.myPopover = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
//UIPopoverArrowDirectionAny
[self.myPopover presentPopoverFromRect:popoverButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
Here's the most important part of the code. If anyone wants help don't doubt to ask it!