colorWithPatternImage creates black lines across view - iphone

Since updating to the latest XCode (although it may be iOS 5.1 related) I have noticed my iPhone now shows black horizontal lines between repetitions of my background image. This does not show on the simulator (normal or retina). Note my iPhone is retina.
I have tried adding a retina version of the background image but this shows the same issue (except the horizontal lines are twice as close to each other due to the resolution change). Another interesting thing is that the lines are only horizontal despite the background image being square, not sure how relevant this is?
Here is the code
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"light_alu.png"]];
I also tried the code listed in this similar question to no avail.
Here is a screenshot of my game with the horizontal black lines (notice there is one right at the very top beneath the toolbar)
What is causing this to happen?

I solved the issue using the answer here. Essentially optimised PNGs cause the issue and re-saving the image without any fancy compression will fix it.

Related

UIImageView is shifting down when viewed on 4 inch iphone

I am trying to figure out what settings for the UIImageView below will work with all device sizes.
I'm getting no luck with every combination I've tried.
Here's the .xib:
When I run this on a 4" the image is shifted down much lower from the top label and the buttons stay put.
I have the top label set to Top, tried Aspect Fit/Fill for it as well, didn't change anything. Seems to be an issue with the UIImageView. Also saw someone mention try clip subviews, have that selected, still can't keep it the same size and orientation when going back and forth from 3.5" to 4" iphone on device and simulator.
Hope this helps, in your case you should keep it to the default setting, no change required..
First if turn off the Autolayout setting from XIB.
Now visit my answer here.

Blurry images when running my application on iPhone

So, I was creating an application for iOS with Xcode 4.2.1, I don't know why all of my icons are blurry, they are in high definition, but for some reason they looks blurry and in a bad quality.
even the background images looks bad..
Please help me, what can I do about it?
This is the original button image:
This is how it looks on the application:
Make sure you saved the high-resolution images with the ending #2x.png, if they aren't they won't work. Also remember that the images needs to be twice the size of the pixles on the screen, that means a 50px x 50px-button will need a 100px x 100px-#2x-file.
Read more about retina icons in the iOS Documentation here.
You should round the origin of each image. If you place image with coordinate like (250.34, 340.21) you get blurry effect.
This is very likely to happen when you use automatic position calculation as well as center property to place your views/images.
In the simulator, use the new Debug menu to check whether your images are misaligned. If they are, use NSRectIntegral to fix their frames.

iPhone 4 adding yellow to stripes to an element

I have an issue with iPhone 4 adding some yellow stripes to an element with a white to grey gradient.
I have attached an image to show what it renders like on the iPhone.
It's not happening on previous versions of the iPhone or android phones.
Does anyone have any idea's as to why this might be happening?
what are the dimensions of the image? I ran across a similair issue before, and I had to play with the image width a bit to get it to scale properly.
I fixed my issue using this: Alpha transparent PNGs not displaying correctly in Mobile Safari
Hope it fixes your issue too!

UITabBar images visible on simulator, disappear on the device

in an iPhone app, I have a UITabBar with three tabs. One has a system image, two more have custom images. These are PNGs, 30x30, palette-based, mostly transparent. These images show up fine in the simulator, but on the device, all I see is a grey gradiented square on a tab. The shapes on these images are grey to begin with, but they do show up as expected on the simulator.
Any ideas, please?
The image should be white on transparent. It's in the UI design guide. In my case, it was grey on transparent. Simulator forgives that, the device does not.
The device itself is pickier about image formats than the simulator is. I've had a number of instances where things showed up in the simulator and didn't on the phone. What has always worked for me is to encode all of my PNGs as 24-bit PNG-24 (in Photoshop) -- for icons and the like, the increased file size is trivial, and it solves my issues with images not showing up.
After about 3 hours I noticed the not so obvious... the name of the file is processed with case sensitive rules on the device, but not within the XCode simulator (As of XCode 4.6).
For example:
If the actual file name (resource) is "first.png" then the following needs to be the case in your code ---
//DO THIS self.tabBarItem.image = [UIImage imageNamed:#"first.png"];
//NOT THIS self.tabBarItem.image = [UIImage imageNamed:#"First.png"];
Look into this first before changing your code.

Interface Builder can't display 160dpi images correctly?

I'm developing an iPhone app. A simple image is the background of the main view.
I've set an UIImageView in the background and set an image in, using IB.
the image is a 160dpi PNG image. It appears like CRAP in IB. When running in the simulator it is ok, crisp.
How am I supposed to work and place my controls precisely on a such poor resolution image ?
Is this a bug ?
Thanks for you help!
IB is not a tool for designing a UI, it is a tool for implementing one. It is designed to perform well rather than display well (this is more important in complex desktop UI design than mobile but the tool is the same for both). The best advice is perhaps to take a cue from the publishing world (where this is a common practice for applications that display large amounts of high resolution graphics such as Adobe InDesign) and keep track of exact measurements for controls - the x,y coordinate positions and height/width. Then you can use the inspector to precisely position controls.
Actually, the DPI is not irrelevant at all.
Change the DPI to 72 and the image will display in IB/Xcode fine.
I don't see anything like this when I work with images in IB. Maybe there's something special about your PNG file? You say that it's 160 dpi, which is fairly irrelevant. More important are what its pixel diomensions are, and how they compare to the screen size.
Maybe the UIImageView is having trouble rendering your PNG, and is for some reason using the preview icon instead? Try a different image, or try resizing your image to 480x320, with 32-bit color.
I am wondering about this as well. I don't think the DPI of the image is what is doing this, because I have a project where everything looks fine in IB on one machine, then on my laptop, it displays the way the OP is describing.
The image dimensions are the same as the iPhone screen and the view dimensions (320x480), but the image displays all tiny instead of filling up the whole dimeal nsions of the UIImageView. If I scale to fill, then the image gets all blurry, at 320x480, even though I can confirm that those are the actual dimensions of the image... It's acting as if the image itself is 320x480 of empty space with a small version of my image centered inside it... this is very strange. As I said- this is the same project that looks completely fine in IB on another machine (and when they build, they both look normal in the simulator). This also happens on my friends's macbook.
Is there some setting in IB that might be the difference?
EDIT:
Guess I spoke too soon- I went back to my other machine and noticed the same problem this time, and it indeed was the dpi. This must have been a change in one of the recent updates to xcode/IB, because I originally never saw this issue, and the image files are exactly the same... strange.