问题
When using the following code:
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"texture1.png"]];
The texture background of my view gets set just fine. But I can see that the images are not scaled properly for a retina display, they seem more pixelated, rather than rich in texture and color as they should be. I have had this issue with other images too, when trying to make an image the size of the iphone 5 screen fade away, only a part of it would be seen, and the rest would be cut off, even though the resolution is fine. Any idea what I am missing here?
EDIT: Does it have to do with the default dpi of the images that I am using?
EDIT #2: Here is a screenshot:

On a side note, does anyone know if good background texture sources besides http://subtlepatterns.com/?
EDIT #3: Here is a good example of me attempting to use the ios-linen pattern

回答1:
firstly remove .png from image name if you are use @2x image
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"texture1"]];
Please check the image height and width for retain display ..
By Apple On devices with high-resolution screens, the imageNamed:, imageWithContentsOfFile:, and initWithContentsOfFile: methods automatically looks for a version of the requested image with the @2x modifier in its name. If it finds one, it loads that image instead. If you do not provide a high-resolution version of a given image, the image object still loads a standard-resolution image (if one exists) and scales it during drawing.
回答2:
Instead of using initWithPatternImage
you should add a UIImageView
to the UIView
. This is better because :-
The
UIImageView
will contain the image according to its specific width and height.Also, the
initWithPatternImage
method consumes MORE MEMORY than theUIImageView
.
I would prefer to use a UIImageView
rather than the
initWithPatternImage:[UIImage imageNamed:@"texture1.png"]
If the image is still not clear you can add the @2x image to the UIImageView
and you will see the clarity is more.
来源:https://stackoverflow.com/questions/16727251/ios-background-and-images-seem-to-not-scale-properly-for-retina-display