Custom UIBarButtonItem icon stretched - ios

I've got a retina and non-retina printer icon. When I just specify 'PrinterIcon.png' on,
[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"PrinterIcon.png"] style:UIBarButtonItemStyleBordered target:self action:#selector(printCmdTouched:)];
it just using the non retina image on my iPad 3 (third generation). If I specifically specify 'PrinterIcon#2x.png' (x lower cased) I don't see it in the toolbar. If I specify 'PrinterIcon#2X.png' it does show in the toolbar but is stretched horizontally.
Anyway know why?
The retina image specs are:
Image Size:40x40
Image DPI: 299.99 pixels/inch
Color Model:RGB
The non-retina image specs are:
Image Size:20x20
Image DPI:72.00 pixels/inch
Color Model:RGB
I checked the specs in Pixelmator.
Attached are the images.
Anyone know why this is not working?
I'm using iOS SDK 5.1
iOS Deployment Target 5.0
Base SDK: Latest iOS (iOS 5.1)

I fixe the issue. I cleaned the build and removed the app from the device before debugging again. Now all good.

Related

stretch old iOS app on iPhone6 Plus screen

I have a very old xcode/objective-c iOS project.
I tried to compile it on the lastest Xcode version and it works fine.
On big iPhones, the application is streched to fit in bigger screen.
I tried to create a new Xcode projet and drag all my source files in the new project. I removed storyboard.
It works, but the application is not stretched. I see 2 black bands at the top and the bottom of the screen.
What i want is just to understand which parameter i have to changed in the project.
This is not a storyboard or size classes issue because i have no storyboard or xib files. I tried to change iOS version déployment target.
Thanks
You need to add a launch image for the large screen size of the plus models or better a launch screen file.
See: here
Add launch images of of accurate sizes as follows for iOS 8 and later.
Goto launchScreen in the XCAssets, you can see these options on the right pane see the image attached.
and add images with size :-
Image type Size
Retina HD 5.5″ 1242 × 2208 pixels
Retina HD 4.7″ 750 × 1334 pixels

Picture is blurred on UIBarButtonItem

I tried to add a picture on an UIBarButtonItem like this :
I did it this way via XCode development interface builder. But, when I launch the application, the picture is blurred like this :
I tried different sizes for this "home" picture, but I have always the same problem with all pictures I tried (Not only this one).
Maybe I forgot something, or there is a "perfect size" I missed ?
Thanks in advance !
*********** EDIT :** Thanks to dariaa I notice I have to import 2 image : home.png and home#2x.png (For the retina compatibility) ********
How do you set the image for your UIBarButtonItem?
I believe if you use this method you should have no problems:
UIBarButtonItem *homeBarButtonItem = [[UIBarButtonItem alloc] initWithImage:yourImage style:UIBarButtonItemStylePlain target:self action:#selector(yourSelector:)];
This way you do not have to worry about sizes.
Just make sure that you have retina version of the image. (you should have "home-25.png"-25x25 pixels image for non-retina devices (if necessary) and "home-25#2x.png"-50x50 pixels image for retina devices.
You can also create an "image set" in your xcassets directory. Import an image and then right-click and select "New Image Set". Once you do this, right-click again in the image box (the image preview on the right) and select iphone, iPad, etc. and fill in all the scaled resolutions of your image.
Xcode will automatically adapt the correct image to be used based on the screen resolution of the device

Custom styling of UINavigationBar not working properly

I am using this code to set custom background image for all UINavigationBars. The problem is that the final image does not appear to be retina size. I researched UINavigationBars are 640x88px. Thats exact dimensions of my UINavigationBar.png however I only see 320x44px on the iPhone Sim(retina) and my iphone 4 which is also retina.
The code that sets the image:
UIImage *background = [UIImage imageNamed:#"UINavigationBar.png"];
[[UINavigationBar appearance] setBackgroundImage:background forBarMetrics:UIBarMetricsDefault];
Here is a screenshot for illustration:
(the difference is there is no bottom dark line as in Photoshop. I can only see half of the image in the iPhone 5 Simulator (Retina))
My question is why this happens and how can I fix it? Thanks.
You need to have two .png files with different size and same name, but with #2x addition in the retina display file.
For example,
File 1 for regular display support:
size- 320x44,
name- UINavigationBar.png
File 2 for retina display support:
size- 640x88,
name- UINavigationBar#2x.png
In your code you always use UINavigationBar.png, the device will automatically know witch file to use, according to the hardware.

Retina display VS normal display color difference

I am designing a custom button with that requires me to overlay a UIButton on top of a UIImageView. The UIImageView uses a [UIImage stretchableImageWithLeftCapWidth:topCapHeight:] image and the UIButton has a background color with a pattern image [UIColor colorWithPatternImage:[UIImage imageNamed:#"buttonPattern.png"]]
The problem I am facing is that on iPhone 4, the images from the UIButton and the UIImageView appear to have slightly different colors although they should match. Testing the same thing on an iPhone 3GS shows normal results without the color difference.
This image shows the difference:
as you can see it looks fine on the 3GS. On the retina display you can clearly see the difference in color. I even tried using the low res images (from the 3GS) on the retina display, the colors were still showing differently. is this a bug in retina display devices? has anyone faced this issue before?
Make sure none of your image files has an embedded color profile. This can be tricky. For Adobe software, this page is helpful:
http://bjango.com/articles/photoshop/

Retina iOS device does not show the #2X image, it shows the 1X image

Retina iOS device does not show the #2X image, it shows the 1X image.
I'm using Xcode 4.2.1 Build 4D502, the app is targeting iOS 5.
I've created a test app (Master/Detail) and added two images.
iconTest.png 24 x 24
iconTest#2X.png 48 x 48
Each image is unique so it I can easily tell which one is being displayed.
In the ViewDidLoad I'm adding a button to the navigation controller...
UIImage *buttonImage = [UIImage imageNamed:#"iconTest.png"];
UIBarButtonItem *button = [[UIBarButtonItem alloc]
initWithImage:buttonImage
style:UIBarButtonItemStyleBordered
target:self
action:#selector(share)];
self.navigationItem.rightBarButtonItem = button;
When I run this test app in the iOS Simulator it correctly displays the icon for a retina iOS device. In the simulator, the Hardware->Device-> is set to iPhone (Retina). And when I pause the app and look at the buttonImage object I can see the scale is set to 2.
This works as expected!
However, when I attach my iPhone 4 and run the app the lower resolution image shows up.
And, when I pause the app and look at the buttonImage object I can see the scale is 1.
This is not the expected behavior.
Any ideas about why this is different between the simulator and the real iOS device?
Is this a known issue? Is there a known workaround?
Thanks,
Brian.
Filenames are case sensitive on the iPhone but not on the iPhone Simulator. You need to use #2x instead of #2X.

Resources