开发者

How to "cascade" image pattern in UIImageView?

开发者 https://www.devze.com 2023-02-14 20:47 出处:网络
I have 开发者_如何学Goan 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\" th

I have 开发者_如何学Goan 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消