0

我已显示 aPopoverViewController但无法正确设置其框架。当我单击一个按钮时,我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)。我想在此按钮下方显示弹出框,并带有指向按钮的箭头标记。但我得到了这样的:

我怎么才能得到它?

4

2 回答 2

0

尝试这个:-

   -(IBAction)products:(id)sender{
UIButton* btn = (UIButton *)sender;
[productsPopover presentPopoverFromRect:[btn bounds] inView:btn permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  }
于 2013-06-27T06:42:51.753 回答
0

而不是自己制作,已经有很多自定义弹出框可以处理你想要的一切,这里是列表。我使用了 WEPopOver,我发现它简单而有用,在计划在您的项目中使用它之前不要忘记检查许可证。

于 2013-02-21T06:29:34.277 回答