Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "cascade" image pattern in UIImageView?

I have an image pattern which I want to display in a UIImageView. The UIImageVIew's size is determined by user-entered text, so its height will change. Is there a way to "cascade" the image pattern, so that it will repeat down the entire height of the UIImageView? In theory I could build a super-tall image in Photoshop, and hope that the image view doesn't get extended past a certain point, but I know that having a basic pattern and repeating it is the smart way to do it. However, I can't find anything related to this in Interface Builder. Is this possible to do, and if so, how can I accomplish it?

like image 748
Jason Avatar asked Mar 05 '11 19:03

Jason


1 Answers

You should be able to accomplish this with a plain UIView. Create a UIColor from the image (this makes a "pattern image", which can be tiled:

UIColor *patternColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"pattern"]];

Then set the background color of the view like so:

view.backgroundColor = patternColor;

I'd run this code in the viewDidLoad or viewWillAppear methods of the view's controller.

like image 123
Carter Allen Avatar answered Nov 02 '22 14:11

Carter Allen