2013-02-21 2 views
0

Я отобразил PopoverViewController, но не смог правильно установить его фрейм. Когда я нажму на кнопку, отобразится PopoverViewController.Frame of 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 «s кадр (450,285,80 30) .Я хочу, чтобы отобразить поповер ниже этой кнопки со стрелкой указывающей в сторону кнопки .Но я получаю так:

Как я могу это получить?

ответ

0

Вместо того, чтобы сделать свой собственный, есть много пользовательских popover уже доступны, которые заботятся обо всем, что вы хотите, here is the list. Я использовал WEPopOver, который я нашел простым и полезным, не забудьте проверить лицензию, прежде чем планировать ее использовать в своем проекте.

+0

Что мне делать, чтобы использовать эти Popovers? –

0

Попробуйте это: -

-(IBAction)products:(id)sender{ 
UIButton* btn = (UIButton *)sender; 
[productsPopover presentPopoverFromRect:[btn bounds] inView:btn permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
    } 
Смежные вопросы