My app has tab bar. I'm trying to customize the tab bar item by changing it's image. I created an image with size 106x49. The image is being placed using this code:
((UITabBarItem*)[self.tabBarController.tabBar.items objectAtIndex:0]).image = [[UIImage imageNamed:#"TabBarItemNow"] imageWithRenderingMode:UIImageResizingModeOriginal];
[((UITabBarItem*)[self.tabBarController.tabBar.items objectAtIndex:0]) setTitle:nil];
When i run the app, the tab bar item image looks like this:
Is there a way to fix this? Am i choosing the right image dimensions for the bar item? Besides, the image looks pixelated when it's presented. I tried it with a larger image, it also go beyond the tab bar.
You've to provide images with the right dimensions. A Tabbar Icon has to be at least 25x25 pixels for a device with a standard resolution and at least 50x50 pixels for high resolution screens.
See the Apple developer library for further reference :
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/IconMatrix
When you're using images.xcassets in your project to manage your images you'll see multiple versions of a image when you import it. E.g.:
Left: 25x25 pixels right:50x50 pixels. When you don't provide images with the right dimensions in your imageset, the compiler will give you a warning.
Related
I'm trying to add my own image as a bar button item, but I don't know how to get the image to scale properly. Apple's Human Interface guidelines recommends that my image be 44x44 px, but when I use a 44x44 px image, it is too large for the toolbar, as you can see:
When I use a smaller version of the image, it looks pixellated on the Retina display. What am I supposed to do here?
In images.xcassets, you can add the images as 1x, 2x and 3x. Xcode will use the appropriate image size depending on the device.
You need to follow apple guidelines for designing you can find it from this link https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/LayoutandAppearance.html#//apple_ref/doc/uid/TP40006556-CH54-SW1
You can find the attached screenshot image for correct sizing for the UIBarButtonItem image size as par the apple guidelines you have to use 44X44 for ratina (#2x) and 22X22 for normal (#1x) for UIBarButtonItem
width 22 pixels X height 22 pixels - ideal for left or right BarButtonItem.
You can resize any image to custom sizes using online tools, one such I used is
http://www.picresize.com/
I created an image which is intended to be used as background image of UIButton. This is what I get:
The image looks great in Photoshop, but when used in iOS application as a button image it looks distorted(the lines are not strait and definitely not as smooth as in the original). How can I avoid this effect?
EDIT:// Preview window
Are you sure that aspect ratios of button and image are the same?
Another thing - use appropriate image size for button image, e.g button view is 30px high, then you need add 30px(#1x), 60px(#2x) and 90px(#3x) images. If you just add an image with 1000px it won't look good, take more disk space and reduce performance.
I have a viewcontroller with a toolbar with 2 bar button items. The image on one is a simple flat icon. The other is a complex image reduced to 28x28 pixels from a 256x256 image. The complex image shows up as a blob as shown below. The actual image is also show in the picture. It is not clear what I am doing wrong. The project code is available in the following link:
Project code
John Griffith on Apple Developer Forum provided this explanation which made a lot of sense. I need to redesign my icons if I want to proceed along this line:
Toolbar images are normally rendering mode "template" - only the alpha channel is used. Any non-transparent pixels are drawn in the bar's tint color. It may be possible to create a UIImage with rendering mode "always original" to preserve the look of your image, but then it won't respond to changes in tint color.
I have downloaded your project. The first thing you should do is to move your image files into the images.xcassets folder. Read here to understand why.
The image you are trying to display is actually just a red rectangle:
As you can see, opening in another program also just displays it as a red rectangle. Be sure to use the correct Image file. The problem lies not with your project but rather the image file you are using.
I am working on an iPhone app that has a tab bar. I made the tab bar icons using a vector graphics editor and exported them to PNG. The icons look fine, except when selected.
This doesn't happen on the retina display.
I use self.tabBarItem.image = [UIImage imageNamed:#"Symbol"]; to set the image.
Here is the actual PNG: http://i.imgur.com/dBTDe.png (though it happens with all the images).
What can I do about this? Why does this happen?
This appears to happen when the images don't have a margin. If you add a margin of 2px it will look fine:
You should have 2 copies of the image. One for normal or older devices, and one for retina display.
Your images should be named accordingly.
image1.png // older devices
image1#2x.png // for retina display. #2x is case sensitive as well
When you choose your image, be sure to choose the normal image. The OS will select the #2x image if it is capable of displaying it.
I'm looking to create my own custom Sort By Date and Sort By Number buttons that I plan on placing in the navigation bar as the right button.
How big should my image be to appropriately fill the space -- the UIBarItem documentation page doesn't list anything about the size the image should be.
As of iOS 11, the Human Interface Guidelines suggest glyphs be about 25×25 points in toolbars and navigation bars, up to a maximum of about 28 points. (And the HIG should definitely be in your bookmarks if you're working on iOS apps!)
That would translate to images 25px square for older devices like iPad 2 / Mini, 50px square for most current devices like iPhone 8 or iPad, and 75px square for Retina HD devices (the iPhone 6/7/8 Plus, or iPhone X). Asset catalogs will help immensely in keeping the different asset sizes organized (and Xcode can even generate them from vector sources these days).
The Human Interface Guidelines tells you this since iOS7:
Regardless of the icon’s visual style, create a toolbar or navigation
bar icon in the following sizes:
About 44 x 44 pixels
About 22 x 22 pixels (standard resolution)
Here is a great matrix of all needed sizes for resources for all platforms
Yes, Apple suggest to use images with 22px, 44px and 66px size for UIBarButtonItems, but if you use preinstalled icons like Bookmark icon, it's sized by 25px 50px and 75px for 1x, 2x and 3x respectively.
Here are 2 icons in UIToolbar. On the right is Apple's system bookmark icon and on the left my custom icon.
Here my custom icon sized 22px-44px-66px:
And here 25px-50px-75px:
So, if you use custom and system icons in one toolbar, I would suggest to use 25px-50px-75px scaling, or your custom icons will be smaller. In fact I always use 25px-50px-75px scaling, it looks better on toolbars, as for me.
Easy: Include your images in Assets.xcassets.
How?
Clic on Assets.xcassets
Clic + icon and then click "New Image Set"
Drag and drop your image to 3x slot
Rename the image set
In the BarButton you can use this name under "Image" field