I have the following code to open a 320px x 320px UIPopoverController, but for some reason the popover is much taller than it should be - about twice the height that I specified (320px).
What's gone wrong?
colorPicker = [[RSColorPickerView alloc] initWithFrame:CGRectMake(20.0, 20.0, 320.0, 320.0)];
[colorPicker setDelegate:self];
[colorPicker setBrightness:1.0];
[colorPicker setCropToCircle:YES];
[colorPicker setBrightness:1.0];
[colorPicker setBackgroundColor:[UIColor clearColor]];
UIColor * aColor = [UIColor colorWithRed:0.803 green:0.4 blue:0.144 alpha:1];
[colorPicker setSelectionColor:aColor];
UIView *newview = [[UIView alloc] initWithFrame:CGRectMake(20.0, 20.0, 320.0, 320.0)];
[newview addSubview:colorPicker];
UIViewController *newviewcontroller = [[UIViewController alloc] init];
[newviewcontroller setView:newview];
UIPopoverController *newpopover =
[[UIPopoverController alloc] initWithContentViewController:newviewcontroller];
newpopover.delegate = self;
[self.colourController setPopoverContentSize:CGSizeMake(320, 320)];
self.colourController = newpopover;
[self.colourController presentPopoverFromRect:CGRectMake(149, 540, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
You need to set the popoverContentSize on the view controller being presented in the popover. You are setting it on the wrong view controller.
newpopover.delegate = self;
self.colourController = newpopover;
[self.colourController setPopoverContentSize:CGSizeMake(320, 320)];
You were doing these last two lines out of order.
Related
Note: Everything worked fine on the older screen sizes however on the new iphone screens (640x1136) things are way to far down
here is the App Delegate initing and showing myRootViewController
myRootViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:[NSBundle mainBundle]];
[myRootViewController.view setFrame:[[UIScreen mainScreen] applicationFrame]];
//NSLog(#"rootviewcontroller1 frame %#", NSStringFromCGRect(myRootViewController.view.frame));
//OUTPUTS: {{0, 0}, {320, 460}}
[window addSubview:myRootViewController.view];
The RootViewController sets the frame for the 'navigationController' and a few other views before adding them to its view.
//NSLog(#"ogtest rootviewcontroller frame2 %#", NSStringFromCGRect(self.view.frame));
//OUTPUTS: {{0, 20}, {320, 548}}
[navigationController.view setFrame:CGRectMake(0, 0, 320,528)];
//I have tried multiples variations including not setting it.
loadingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[loadingView setBackgroundColor:[UIColor clearColor]];
UILabel *_loadingLable = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 80.0f, 20.0f)];
_loadingLable.backgroundColor = [UIColor clearColor];
_loadingLable.textColor = [UIColor whiteColor];
_loadingLable.text = #"Loading...";
[_loadingLable setCenter:CGPointMake(181.0f, 240.0f)];
activityIndicatior = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[activityIndicatior setCenter:CGPointMake(120.0f, 240.0f)];
RoundedView *_roundedRectangle = [[RoundedView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 140.0f, 50.0f) roundedCorner:RoundedCornersTypeALL];
_roundedRectangle.center = CGPointMake(160.0, 240.0);
_roundedRectangle.rectColor = [UIColor blackColor];
_roundedRectangle.alpha = 0.7;
[loadingView addSubview:_roundedRectangle];
[loadingView addSubview:activityIndicatior];
[loadingView addSubview:_loadingLable];
[_loadingLable release];
[_roundedRectangle release];
[loadingView setHidden:YES];
[self.view addSubview:[navigationController view]];
[self.view addSubview: loadingView];
You can see from the image below that the grey bar is there for the nav bar. The text "Tuesday 30 Apr...." with the arrow buttons should occupy that grey area and not 2 cells from the top.
If you find yourself setting the frame of your navigation controller / navigation bar, you're doing something wrong.
Most of the time, you don't even need to set the frame of your view controller's view either.
Your app delegate needn't be any more complicated than this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self setWindow:[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]];
[[self window] setRootViewController:[[UINavigationController alloc] initWithRootViewController:[[RootViewController alloc] init]];
[self.window makeKeyAndVisible];
return YES;
}
It will most likely be a setting in your RootViewController nib. For the first view in the "Objects" list on the left, you have probably set the Top Bar property.
I ended up creating separate xib files with
_iPhone_Retina
at end of the file name
Which also called for statements like this
if (IS_IPHONE_RETINA) {
View = [[View alloc] initWithNibName:#"View_iPhone_Retina" bundle:[NSBundle mainBundle]];
}else{
View = [[View alloc] initWithNibName:#"View" bundle:[NSBundle mainBundle]];
}
and IS_IPHONE_RETINA is defined in the projectname.pch file as
#define IS_IPHONE_RETINA ([[UIScreen mainScreen] bounds].size.height == 568 )
in ipad the select tag is showed in pop up in a widget wheel. I want to use the normal select tag abd disable that feature in ios . Check this link to understand better what i mean : http://alvinalexander.com/iphone/iphone-ipad-html-select-widget-wheel .
see the following code hope it will help you...enjoy code
-(void)showPicker{
UIToolbar *toolPicker = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
toolPicker.barStyle = UIBarStyleDefault;
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:#selector(hidePicker)];
[toolPicker setItems:[NSArray arrayWithObjects:cancelButton, nil]];
pickerCategory = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
pickerCategory.delegate=self;
pickerCategory.dataSource=self;
pickerCategory.showsSelectionIndicator = YES;
txtCategory.inputView=pickerCategory;
[pickerCategory addSubview:toolPicker];
CGRect thePickerFrame = pickerCategory.frame;
thePickerFrame.origin.y = toolPicker.frame.size.height;
[pickerCategory setFrame:thePickerFrame];
UIView *view = [[UIView alloc] init];
[view addSubview:pickerCategory];
[view addSubview:toolPicker];
UIViewController *vc = [[UIViewController alloc] init];
[vc setView:view];
[vc setContentSizeForViewInPopover:CGSizeMake(320, 260)];
popover = [[UIPopoverController alloc] initWithContentViewController:vc];
[popover presentPopoverFromRect:txtCategory.bounds inView:txtCategory permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
-(IBAction)hidePicker{
[popover dismissPopoverAnimated:YES];
}
I'm presenting a UIPopover from a UIButton but my app is crashing at line [popoverController presentPopoverFromRect:[button bounds] inView:button permittedArrowDirections:UIPopoverArrowDirectionRight animated:NO];
- (IBAction)birthdayButtonClicked:(id)sender
{
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 344)];
popoverView.backgroundColor = [UIColor whiteColor];
UIDatePicker *datePicker = [[UIDatePicker alloc]init];
datePicker.frame = CGRectMake(0, 44, 320, 300);
[popoverView addSubview:self.view];
[popoverView addSubview:datePicker];
popoverContent.view = popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 244);
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
UIButton *button = (UIButton *)sender;
[popoverController presentPopoverFromRect:[button bounds] inView:button permittedArrowDirections:UIPopoverArrowDirectionRight animated:NO];
[popoverView release];
[popoverContent release];
}
It is not a good idea to add self.view as subview. UIView object can be displayed only once in every current mooment, you cannot show popover with content as self.view in self.view. If you really need to perform this task then try to make copy of required views.
Change the inView to self.view. inView means in which UIView you want to present popover.
presentPopoverFromRect:[button bounds] inView:**self.view** permittedArrowDirections:UIPopoverArrowDirectionRight animated:NO];
In my app when I download something from service, I show progress indicator:
- (void)setupProgressIndicator {
MBProgressHUD *progressHUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:progressHUD];
self.progressIndicator = progressHUD;
[progressHUD release];
}
[self.progressIndicator show:YES];
My view has Navigation Bar which I setup in my AppDelegate, and when indicator is shown, I still can tup on Navigation Bar Buttons...Can MBProgressHUB cover whole screen ??? Because I don't want to disable buttons on sync start and than make them enable on sync finish...I think indicator should cover whole screen. Any ideas ? Thanks...
Here is my implementation use it if you want
Put it in appDelegate and use from anywhere in the application.
#pragma mark -
#pragma mark Waiting View
- (void)showWaitingView {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGRect frame = CGRectMake(90, 190, 32, 32);
UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[progressInd startAnimating];
progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
frame = CGRectMake(130, 193, 140, 30);
UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame];
waitingLable.text = #"Processing...";
waitingLable.textColor = [UIColor whiteColor];
waitingLable.font = [UIFont systemFontOfSize:20];;
waitingLable.backgroundColor = [UIColor clearColor];
frame = [[UIScreen mainScreen] applicationFrame];
UIView *theView = [[UIView alloc] initWithFrame:frame];
theView.backgroundColor = [UIColor blackColor];
theView.alpha = 0.7;
theView.tag = 999;
[theView addSubview:progressInd];
[theView addSubview:waitingLable];
[progressInd release];
[waitingLable release];
[window addSubview:[theView autorelease]];
[window bringSubviewToFront:theView];
[pool drain];
}
- (void)removeWaitingView {
UIView *v = [window viewWithTag:999];
if(v) [v removeFromSuperview];
}
usual thing is to add an transparent view cover the entire screen and that will capture touch event. or you can make your HUD the size of the screen, with visible widget only in the center.
- (IBAction)showWithCustomView:(id)sender {
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"37x-Checkmark.png"]] autorelease];
HUD.customView.frame=CGRectMake(0, 0, 320, 460);//Ur answer
HUD.mode = MBProgressHUDModeCustomView;
HUD.delegate = self;
HUD.labelText = #"Completed";
[HUD show:YES];
[HUD hide:YES afterDelay:3];
}
I want to show a popover with a custom contentsize.
I can do it doing like so
UINavigationController* popoverContent = [[UINavigationController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 800, 800)];
popoverView.backgroundColor = [UIColor blueColor];
popoverContent.view = popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(55, 55);
UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[pop presentPopoverFromRect:CGRectMake(80.0, 210.0, 160.0, 40.0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
but if I change the content to :
popoverContent.viewControllers = [NSArray arrayWithObject:myViewController];
the
popoverContent.contentSizeForViewInPopover = CGSizeMake(55, 55);
the size doesn't change at all.
How can I change the content size while using the navigation controller?
Thanks
Explicitly changing the popovers size works:
[self.popoverController setPopoverContentSize:myView.size animated:YES];
But I agree that contentSizeForViewInPopover should work. It doesn't for me anyway.