我想在用户按下按钮时显示带日历的弹出窗口。我看过很多弹出窗口,但它们不包括按下按钮的箭头。我想要一些类似于下图的东西。我做了一个日历,我不知道如何将它插入到弹出窗口中。有人可以给我一招吗?
我知道如何使用tableview创建一个popover但是没有使用其他viewcontroller。
谢谢!
答案 0 :(得分:0)
我已经解决了我的问题。我将逐步解释它:
1-首先,我创建了一个popover 2-然后我在项目中加入calendar 3-然后我将日历视图添加到弹出窗口
以下是代码:
- (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];
}
这是代码中最重要的部分。如果有人想要帮助,不要怀疑问它!