我显示了PopoverViewController
但无法正确设置其框架。当我点击按钮时,我的PopoverViewController
将会显示。
-(IBAction)AddTheTimePicker:(id)sendar {
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
UIButton *button = (UIButton *)sendar;
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView *popoverView = [[[UIView alloc] init]autorelease]; //view
popoverView.backgroundColor = [UIColor blackColor];
DatePicker=[[[UIDatePicker alloc]init]autorelease];//Date picker
DatePicker.frame=CGRectMake(0,44,320, 216);
DatePicker.datePickerMode = UIDatePickerModeDate;
[DatePicker setTag:10];
UIToolbar *pickerDateToolbar = [[[UIToolbar alloc] initWithFrame:[self isViewPortrait]?CGRectMake(0, 0, 320, 44):CGRectMake(0, 0, 320, 44)]autorelease];
pickerDateToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerDateToolbar sizeToFit];
NSMutableArray *barItems = [[[NSMutableArray alloc] init]autorelease];
UIBarButtonItem *doneBtn = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dateChanged:)]autorelease];
[barItems addObject:doneBtn];
UIBarButtonItem *flexSpace = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]autorelease];
UILabel *toolBarItemlabel;
if([self interfaceOrientation] == UIInterfaceOrientationPortraitUpsideDown || [self interfaceOrientation] == UIInterfaceOrientationPortrait)
toolBarItemlabel= [[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 180,30)]autorelease];
else
toolBarItemlabel = [[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200,30)]autorelease];
[toolBarItemlabel setTextAlignment:UITextAlignmentCenter];
[toolBarItemlabel setTextColor:[UIColor whiteColor]];
[toolBarItemlabel setFont:[UIFont boldSystemFontOfSize:16]];
[toolBarItemlabel setBackgroundColor:[UIColor clearColor]];
UIBarButtonItem *buttonLabel =[[[UIBarButtonItem alloc]initWithCustomView:toolBarItemlabel]autorelease];
[barItems addObject:buttonLabel];
[barItems addObject:flexSpace];
UIBarButtonItem *SelectBtn = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(DatePickercancelClick:)]autorelease];
[barItems addObject:SelectBtn];
[pickerDateToolbar setItems:barItems animated:YES];
[popoverView addSubview:DatePicker];
[popoverView addSubview:pickerDateToolbar];
popoverContent.view = popoverView;
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate=self;
[popoverContent release];
[popoverController setPopoverContentSize:CGSizeMake(320, 264) animated:NO];
[popoverController presentPopoverFromRect:[sendar frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
}
UIButton
的框架为(450,285,80 30)
。我想在此按钮下方显示弹出框,箭头标记指向按钮。但我得到这样的结果:
我怎样才能得到它?
答案 0 :(得分:0)
而是制作自己的,有很多自定义弹出窗口可以处理你想要的一切,here is the list。我使用了WEPopOver,我发现它简单实用,在计划在项目中使用之前不要忘记检查许可证。
答案 1 :(得分:0)
试试这个: -
-(IBAction)products:(id)sender{
UIButton* btn = (UIButton *)sender;
[productsPopover presentPopoverFromRect:[btn bounds] inView:btn permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}