I am doing one iphone app. In this app i want to disable the back navigationleftbarbutton. I have used this below code for disable the navigationleftbarbutton but it is not working. Now i have created one view and i have added in uinavigationbar. But now i want to make that view in transparent view. And also how can i remove my customview(myview1) from the navigationbar. I have attached my code. please some body help me to solve my issue.
Disable Code:
self.navigationItem.leftBarButtonItem setEnabled:NO];
And This is my customview Code:
myview1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
myview1.backgroundColor = [UIColor redColor];
button = [[UIBarButtonItem alloc]initWithCustomView:myview1];
self.navigationItem.leftBarButtonItem = button;
How can i make myview is transparent view. And how can i remove mycustomview(myview1) from navigationbar. Thanks in advance.
you can hide navigation back button by writing code below:
self.navigationItem.leftBarButtonItem.hidden = YES;
and your view ie myview can be transparent by changing alpha value of the view
[myview setAlpha:0.3]; //alpha value ranges from 0 to 1
By settign alpha value 0.0 makes view transparent and increases transparency as u increases alpha value
Related
I am trying to use the background view of the image view of a UIButton but for some reason it will not show up. This is what I have tried:
detailCell.greenPriorityButton.imageView.frame = detailCell.greenPriorityButton.frame;
[detailCell.greenPriorityButton.imageView setBackgroundColor:[UIColor greenColor]];
[detailCell.greenPriorityButton.imageView setHidden:NO];
[detailCell.greenPriorityButton.imageView setOpaque:YES];
I have called NSLog on the imageView property and it seems everything is as it should be. I can also tap on the button and the method associated with it will be called so I know it exists. Just in case I am missing something here is the NSLog return:
<UIImageView: 0x1d97e1b0; frame = (254 61; 20 20); clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x1d97e210>>
The reason I am not using dot notation to set the image view properties above is because they don't seem to change the values. For example, if I say detailCell.greenPriorityButton.imageView.hidden = NO; it doesn't seem to do anything.
Thanks for any help!
Edit
The reason for not just setting the background color of the button and not its image view is because I am trying to create a small shape in the button. However I want the tappable space to have margins around the shape so it is still user friendly. I thought the image view property would lend useful as I could manipulate the frame and layer of that separately from the frame and layer of the button.
I have now tried adding a UIView *greenBackground as a subview to the button, however this doesn't appear either.
If you want a view that you can have within the view of the button for the purpose of setting its color then I would think that trying to use the imageview is the wrong approach. You could just add a subview that has the changed background color. something like this:
UIView *colorView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 10, 10)];//Whatever rect you want that will be in reference to the frame of the button
colorView.backgroundColor = [UIColor greenColor];
[detailCell.greenPriorityButton addSubview:colorView];
I'm adding a series of buttons to a UINavigationBar using:
NSArray *items;
items = [NSArray arrayWithObjects:
fixedSpace,
refreshStopBarButtonItem,
flexibleSpace,
self.backBarButtonItem,
flexibleSpace,
self.forwardBarButtonItem,
flexibleSpace,
self.actionBarButtonItem,
fixedSpace,
nil];
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, toolbarWidth, 44.0f)];
toolbar.items = items;
toolbar.tintColor = [[UIColor whiteColor] colorWithAlphaComponent:1.0];
toolbar.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
All working well.
However when I rotate to landscape mode the toolbar within the uinavigationbar doesn't rotate.
Adding this code (found on SO) causes the toolbar to resize but not the buttons within it, so they are partially cropped at the bottom and no longer lines up with the toolbar background
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
CGRect navigationToolbarFrame = self.navigationController.navigationBar.frame;
CGRect customToolbarFrame = CGRectOffset(navigationToolbarFrame, 0.0, navigationToolbarFrame.size.height);
[UIView animateWithDuration:duration animations:^{
//self.toolbar.frame = customToolbarFrame;
// FAILS!!!
//self.navigationItem.rightBarButtonItem.toolbar.frame = customToolbarFrame;
// FAILS!!!
}];
}
What is the correct way to address the toolbar within the uinavigationbar?
Something like...
self.toolbar.frame = customToolbarFrame;
Or do I have to specify a autoresizemask for the UIBarButtonItems?...
self.backBarButtonItem.autoresizingMask = UIViewAutoresizingFlexibleHeight;
... trying to do so like this fails
Very curious because this code rotates toolbar fine when I include it in my code. No problem rotating the toolbar.
I assume your view controller is responding to shouldAutorotateToInterfaceOrientation? Could you include screen snapshot of what you're seeing?
Are you doing any UIToolbar category/subclass to eliminate its border? (I just subclass with empty (void)drawRect:(CGRect)rect to get rid of border, but I tried both that and the standard UIToolbar and both rotated fine.) Anyway, if you're doing subclass/category of UIToolbar, please include that code?
Also, you could alternatively just use iOS 5's rightBarButtonItems and bypass the toolbar altogether, e.g. self.navigationItem.rightBarButtonItems = items; will then add the array of UIBarButtonItem objects to the navigation bar.
This is a bit of a long shot, but how is your view controller being loaded? Some people try bypassing presentViewControllerAnimated and/or pushViewController and instead simply create a view controller, grab its view, add it as a subview of the previous view controller's view. Unfortunately, this ends up with a disconnect between the view controller hierarchy and the view hierarchy, and according to WWDC 2011 session 102 on view controller containment, this can prevent rotation events from being transmitted correctly. Make sure you're using presentViewControllerAnimated or pushViewController if this isn't your root view controller.
I don't do any of that willAnimateRotationToInterfaceOrientation or subsequent code, just the simple UIToolbar and it works fine during rotation, so I wonder if the problem rests elsewhere.
I have a custom image header ABOVE the uinavigationbar. I do this with this code:
self.navController.view.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
self.navController.navigationBar.frame = CGRectMake(0.0, 73.0, 320.0, 44.0);
UIView *checkNav = [self.navController.view viewWithTag:9999];
if (checkNav == nil) {
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"header-logo.jpg"]];
imgView.tag = 9999;
[imgView setFrame:CGRectMake(0.0, 23.0, 320.0, 50.0)];
[self.navController.view addSubview:imgView];
}
This works great. But, when the app goes inactive (hit the main iphone home button) and then you go back into the app, the uinavigationbar shifts up to the default place at the top of the screen and is hidden behind my custom header image.
I've tried throwing code into applicationDidBecomeActive, but it doesn't help. Any help would be greatly appreciated.
Thanks!
You do get warned about this in the docs:
With only a few exceptions, you should never modify the navigation bar object directly. It is permissible to modify the barStyle or translucent properties of the navigation bar but you must never change its frame, bounds, or alpha values directly
Having said that, you should be able to get the effect by repeating your above code in applicationDidBecomeActive or applicationWillEnterForeground, assuming you have a pointer to the navigation controller from there. You may find that hiding and re-showing the navigation bar is required (bit of a hack, but it can help - I had a similar problem with hiding / showing the status bar and the navigation bar not going to its correct place)
What about putting the code into viewWillAppear?
Hi all I am trying to add a UITextField to my cameraOverlay. I am getting it to show up on my camera view, but it is not editable. Its not responding at all. What approach do I need to take to get it to repsond?
I have looked at this questions, but do not understand how to set a transparent View Controller on top of my cameraOverly.
Suggestion for camera overlay
Thanks in advance!
Steps should be:
Create your picker.
Create an empty view with clearColor background.
Add your textfield with addSubview: to the view in step 2.
Set cameraOverlayView to the view created in step 2.
Present your picker.
In code:
//self.picker and self.textField being your UIImagePickerController and UITextField instances.
emptyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; //This frame will make it fullscreen...
emptyView.backgroundColor = [UIColor clearColor];
[emptyView setAlpha:1.0]; //I think it is not necessary, but it wont hurt to add this line.
self.textField.frame = CGRectMake(100, 100, self.textField.frame.size.width, self.textField.frame.size.height); //Here you can specify the position in this case 100x 100y of your textField preserving the width and height.
[emptyView addSubview:self.textField];
self.picker.cameraOverlayView = emptyView; //Which by the way is not empty any more..
[emptyView release];
[self presentModalViewController:self.picker animated:YES];
[self.picker release];
I typed the code here myself so it could have some typo, Hope it helps!
i have a UIView that is smaller than the superview so i can represent this view as a modal view when a button is clicked.
I have managed to do the following:
* add a subview to the superview.
* centered this modal view
I am now trying to make the elements behind the UIView unclickable. And also add a grey shadow te the ourside of my modal view so that the user understands that the modal view is the view in focus.
I would like to know how to achieve this.
I do not wish to use the presentation modal transition. I know and have already implemented this in other projects.
Any help is appreciated.
The simplest thing would be to lay a fullscreen UIView with a translucent gray background behind your "modal" view. Then it will intercept all of the touches. It might look something like this:
UIView *dimBackgroundView = [[UIView alloc] initWithFrame:theSuperview.bounds];
dimBackgroundView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:.5f];
[theSuperview addSubview:dimBackgroundView];
[theSuperview addSubview:modalView];
For future reference, you can set myView.userInteractionEnabled = NO to disable touch events on a view.
There are several ways to do it.
If you have a custom view which has custom location, you can modify it like that:
Create an instance var:
UIView* backgroundView;
And whenever you need it, put it behind your custom view:
if (backgroundView == nil)
backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width)];
backgroundView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:.5f];
[self.view addSubview:backgroundView];
[backgroundView animateBump:customView.view];
[backgroundView addSubview:customView.view];
When you do not need it anymore
[backgroundView removeFromSuperview];