I'm using custom images for UINavigationBars and UIToolbars. The problem i'm having is on 1 of my views that uses a UINavigationBar, the right button appears too tall
On the views that use a UIToolbar (modal views so no Nav bar) they look fine
What could be causing the button to be too large? I've tried adding the button in IB and also using code. Then set the image like this
UIImage *barButton = [[UIImage imageNamed:#"ButtonBlue"] resizableImageWithCapInsets:UIEdgeInsetsMake(6, 8, 6, 8)];
[self.connectButton setBackgroundImage:barButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Thanks
Create a smaller button. You can do this in Preview - resize it. Make sure you have #2x sizes too. T cannot recall the recommended size for theses images - it's something like 30 points or so (search and you'll find it for sure).
Related
I'm looking on the internet and I'm told that the sizes should be 320x44 and 640 x 88, but I tried these and I have the following result:
The duplicate image to fill the entire space of the navigation bar, which are the correct sizes and as an achievement also that does not cover the state bar. Thank in objective C
If you are attempting to add color overlay customize navigation controller and add subview with autolayout. It worked for me to place a logo in one of my project.
Your image has the wrong mode.
When you are setting your image, use the following to create the bars image for the appropriate fill / layout mode:
UIImage *barImage = [[UIImage imageNamed:#"imageName"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)
resizingMode:UIImageResizingModeStretch];
Now you can go about setting your navigation bars background image with either UIBarMetricsDefault or UIBarMetricsDefault
[[UINavigationBar appearance] setBackgroundImage:barImage forBarMetrics:(UIBarMetrics)];
OR if you are just setting this within your view controller with a parent navigation controller:
[self.navigationController.navigationBar setBackgroundImage:barImage forBarMetrics:(UIBarMetrics)];
This will set your image as the background image with the correct resizing to ensure it fills the entire navigation bar. Happy coding!
I've set my UINavigationBar background image to some image, like this:
UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:#"Menubar.png"];
[navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
but I cant really see the whole image since its bigger than the default size on a UINavigationBar.
So two things please:
How to set a UINavigation size to fit the background image size?
I dont want to see the battery and time bar in the background, so my image will cover it.
It's not possible to set UINavigation size (take a look at this question), you have to fit the background image instead
It's impossible to cover the status bar, but you can easily hide it. See the example here
you can easily remove status bar using info.plist file
just addRow and write "Status bar is initially hidden" and set value "YES"
end check to navigationBar
iOS. How to change UINavigationBar height and change frames of the others subviews at once?
I'm trying to customise the navigation bars throughout my app.
The navigation controller has been created in IB.
I used the following code to add a custom image to the bar. The image is 320 x 44 points.
This code is in the AppDelegate in applicationDidFinishLaunchingWithOptions:
UIImage *navBackgroundImage = [UIImage imageNamed:#"Nav Image.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
The problem is that on the simulator, the bar now covers half the screen! And covers up a load of content. Ive tried messing around with the image dimensions in Photoshop and it helps, but their must be an easier way than messing around and rebuilding with trial and error?!!
Are there any convenience methods that set the size of the nav bar?
Any help much appreciated!!
Maybe it is a layer Rasterization issue :
check if there is :
layer.shouldRasterize = YES;
layer.rasterizationScale = [UIScreen mainScreen].scale;
somewhere in your code and try commenting those lines.
(these lines are often linked to shadows to improve the performance when displaying them).
A quick solution is to go to the NIB file and select UINavigationControler -> Size Inspector -> TurnOff Autoresizing.
In my iOS 5+ app, I use a custom navigation bar image, with custom navbar buttons.
First of all, here is how I tell my app to use the images :
In AppDelegate.m :
UIImage *navBarImage = [UIImage imageNamed:#"Navbar"];
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault];
UIImage *barButton = [[UIImage imageNamed:#"Nav-button"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
[[UIBarButtonItem appearance] setBackgroundImage:barButton forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
So, the images are used. Great. But, there are a couple of things happening :
• First, on my button, under the bottom corners, au few white pixels appear (they're not on the original image, that's for sure). I also use a custom back button, and same thing happens. This seems to be more visible under iOS 6 than iOS 5.
• When I open a modal VC, the navigation bar is "filled up to the status bar" with white pixels. Only for a modal VC.
Here are screenshots of the situation.
iOS 5 , main VC.
iOS 5, modal VC.
iOS 6, main VC.
iOS 6, modal VC.
So, what can I do ? The white pixels under the buttons are not highly visible (a bit more for the back button), but I really want a nice design for the app, and this doesn't contribute at all..
Concerning the modal VC, I can use a "rectangle" image, which could cover the white pixels, but again, regarding design consistency, I'd prefer to use only one navigation bar..
As always, any explanation / solution / hint is greatly appreciated ! ;)
Thanks.
EDIT :
I just noticed that under iOS 6, the white pixels on top of the navigation bar are rounded, as the navigation bars in iOS 6.. Strange.. :)
Hm! just for testing purpose, can you download the following sample image for a navigation bar background and try this image instead? Just let us now how it looks with this image.
I'm just guessing, but i suppose your image is not pixel perfect for the navigation bar dimensions! Probably a few pixels below the optimum height for the navigation bar.
I have a UITableViewController. I want a "toolbar-ish" component at the bottom.
I started by using a background image and a button. In interface builder, I added them to the bottom of the iPhone screen. The problem I ran into was that the background image and button scrolled with the table. I obviously need this fixed at the bottom.
Not finding too much direction online, I decided to customize a UIToolbar to look how I want since the position is fixed by default. In my initWithNibName for my UITableViewController, I have:
UIImage *shuffleButtonImage = [UIImage imageNamed:#"shuffle_button.png"];
NSArray* toolbarItems = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithImage:shuffleButtonImage
style:UIBarButtonItemStylePlain
target:self
action:#selector(push:)],
nil];
[toolbarItems makeObjectsPerformSelector:#selector(release)];
self.toolbarItems = toolbarItems;
The problem I am running into now is that the "shuffleButtonImage" is not showing up properly. The shape of the button shows up fine but it is colored white and therefore does not look like the image.
Does anyone know why a "white image" would be showing instead of the actual image?
Also does it sound like a good idea to customize a UIToolbar or is there a simple way to ensure a fixed position "toolbar-ish" component.
To reiterate - my "toolbar-ish" component only needs to be one button at the button of my UITableView. The single button has a gradient color background that I create with an image.
From the description of the "image" parameter in the documentation for the initWithImage:style:target:action: method of the UIBarButtonItem class:
The images displayed on the bar are derived from this image. If this image is too large to fit on the bar, it is scaled to fit. Typically, the size of a toolbar and navigation bar image is 20 x 20 points. The alpha values in the source image are used to create the images—opaque values are ignored.
Basically, the image you provide is used as a mask to create an outline/shadow for the actual button image. I do not believe you can change this behavior for a UIBarButtonItem.
As an alternative, you can create a UIButton (with your color image) and then set it as the custom view for your UIBarButtonItem, as suggested here. If you go that route, setting the bounds of the UIButton to match the bounds of the UIBarButtonItem might also be necessary (see this discussion).
Your image may be showing up blank because it's not being found in your resources. Put a breakpoint after your definition of shuffleButtonImage and check it's not nil.