what is the appropriate way to overlay two layers of an UIView for the iPhone? The underlaying view should be active until a button is pressed, then another UIView should cover
everything in a transparent way.
I found the Modal View Controllers, but they simply exchange UI-Views but don't overlay.
Thanks in advance.
Chris
You should use [existingView addSubview:newView]; to add a view to an existing view. the newView will appear on top of the existingView. So conceptually, you would create a button on existingView, connect it to an IBAction that calls a method like this:
CGRect newSize = CGRectMake(0.0f ,0.0f, 320.f, 400.0f);
UIView *newView = [[UIView alloc] initWithFrame:newSize];
[existingView addSubview:newView];
[newView release];
This will place a newView on top of the existingView.
following is a simple 3 line ARC-compatible with transparent overlay for UIView
_overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
_overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
[self.view addSubview:_overlayView];
Related
I am trying to add UIToolbar as titleview for navigationitem. toolbar has been sucessfully added on titleview. but seems like frame is not getting set properly.
above is output I am currently getting. I am not setting right/left bar button.
Thanks.
instead of assigning to titleview, add it as a subview
[navigationController.navigationBar addSubview:toolBar];
if it not works then do like following
create one view like this
UIView *yourView = [[UIView alloc] initWithFrame:navigationController.navigationBar.bounds];
yourView .backgroundColor = [UIColor yellowColor];
[yourView addSubView:toolBar];
ctrl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[navigationController.navigationBar addSubview:yourView];
I have created a UIScrollView and am now trying to place a UIButton over the scroll view. However when I build and run the application the scroll view still works fine but I cannot see the UIButton.
I link the UIButton IBOutlet inside the interface builder.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
scrollView.backgroundColor = [UIColor blackColor];
scrollView.delegate = self;
scrollView.bounces = NO;
backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"auckland-300.jpg"]];
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"249a-134206f1d00-1342071f5d9.ImgPlayerAUCKLAND.png"]];
// Note here you should size the container view appropriately and layout backgroundImage and image accordingly.
containerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,601,601)];
playButton = [[UIButton alloc] init]; //test button cannot see it.
[containerView addSubview:backgroundImage];
[containerView addSubview:image];
scrollView.contentSize = containerView.frame.size;
[scrollView addSubview:containerView];
scrollView.minimumZoomScale = 0.5;
scrollView.maximumZoomScale = 31.0;
[scrollView setZoomScale:scrollView.minimumZoomScale];
self.view = scrollView;
}
Any help would be appreciated
Everything seems ok. But I think the reason you are not able to see the button playButton is because you are not adding it to the view itself.
Dont you need to do this ? [containerView addSubview:playButton];
To help you out, here's what I do for debugging -
UIView implements a useful description method. In addition, it
implements a recursiveDescription method that you can call to get a
summary of an entire view hierarchy.
NSLog(#"%#", [controller.view recursiveDescription]);
The button is probably in the nib that you linked the controllers view to, right? By assigning the scrollview to the view, you remove the view from
The nib from the controller, that's why you can't see te button or press it.
You can either place the button in the scrollview or you add both scrollView and thenthe playButton as subviews of self.view.
Maybe you want to rethink your design tho.
Placing a button over a scrollview doesn't really seem like good practice to me.
I have a 320x460 view with a number of buttons, depending on the button pressed, a 280x280 view pops up over the 320x460 view (similar to the behavior of the UIAlertView) using code like this:
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(20, 200, 280, 280)];
overlayView.backgroundColor = [UIColor whiteColor];
[overlayView autorelease];
[overlayView addSubview:label]; // label declared elsewhere
[overlayView addSubview:backgroundImage]; // backgroundImage declared elsewhere
//... Add a bunch of other controls
[label release];
[backgroundImage release];
//... Release a bunch of other controls
[self.view addSubview:overlayView];
Everything works fine displaying the overlayView and all its controls.
The question I have is, how do I get rid of the overlayView once it's displayed? I want to make it not only not visible but to remove it completely, since the user will be popping up the overlayView repeatedly during use.
You need access to overlayView to remove it, I'd suggest adding this to the create side:
overlayView.tag = 5; // Or some other non-zero number
Then later you can use it like this:
-(void)removeOverlayView
{
UIView *overlayView = [self.view viewWithTag:5];
[overlayView removeFromSuperview];
}
I have created a UIViewController class with a background color as red.
I have also created a UIView which is a subview and placed with a background image and two UIButtons on them.
The coding which i give for screen orientation is
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
self.view =[[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
self.view.backgroundcolor =[UIColor redColor];
UIView *subview;
subview = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
subview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#""]];
subview.autoresizingMask = UIViewAutoResizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;
Problem:
When i turn into Landscape the subview is resized with the image, but the buttons remain in the same position and i am not using any .xib file.I have created the project programmatically.Please do reply....
Override layoutSubviews for your class. You might need to explicitly call [self setNeedsLayout] from didRotateFromInterfaceOrientation
How can I change the line's color that separates the navigation bar and the view?
For instance flickr changed it to gray (http://www.geardiary.com/wp-content/uploads/2009/09/Screen-shot-2009-09-08-at-8.00.06-AM.png)
By default mine is always black...
Thanks in advance for your help,
nico
They used a custom bottom bar and not the Apple provided ones. I dont know your setup, but if you can make or draw your own custom view however you want (you can do this), and stick buttons on it (you can do this too), then you have a toolbar
#define TOOLBAR_HEIGHT 44
CGRect frame = CGRectMake(self.view.bounds.size.height - TOOLBAR_HEIGHT, 0.0, self.view.bounds.size.width, TOOLBAR_HEIGHT);
UIView *customBottomBar = [[UIView alloc] initWithFrame:frame];
[customBottomBar setBackgroundColor: [UIColor grayColor]];
UIButton *button = [[UIButton alloc] initWithFrame:<frame goes here>]
... <button setup>
[customBottomBar addSubview:button];
[button release];
...<more buttons>
...<more buttons>
[self.view addSubview:customBottomBar];
[customBottomBar release];
And to answer your question, you can add whatever you want to any view, so while the way I just suggest is the most customizable, you might just want to place a 1pixel high colored bar at the right spot (on top of the existing toolbar) by doing this:
CGRect frame = CGRectMake(self.view.bounds.size.height - TOOLBAR_HEIGHT, 0.0, self.view.bounds.size.width, 1);
UIView *customLine = [[UIView alloc] initWithFrame:frame];
[customLine setBackgroundColor: [UIColor grayColor]];
[self.view addSubview:customLine];
[customLine release];