Stretchable and Pattern UIImage at the same time

I would like to encode a shelf, and I don't want to think about resizing and changing background images when rotated and depending on the screen (iPad / iPhone). Is it possible to create an image that stretches horizontally but repeats vertically? So far, I have found only [UIColor colorWithPatternImage:] and [UIImage strechableImageWithLeftCapWidth:topCapHeight:] or the new [UIImage resizableImageWithCapInsets:] . But I couldn't let them work together, obviously.

I hope this illustration helps to understand my problem:

Illustration

Do you have any idea how to accomplish the above so that it works with one image for different sizes and orientations? Thanks!

+7
source share
3 answers

[UIColor colorWithPatternImage:] can occupy a very large amount of memory when working with a large number of lines. In the end, I created one kind of image that was one line larger than the whole view using [UIColor colorWithPatternImage:] , and then shifted that view up or down the line, if necessary, to view the scrolling frame by frame. Since the view was moved only at line boundaries, the performance was much better than I expected.

However, the best option would be to create a pool of individual UImageViews using [UIColor colorWithPatternImage:] and split them, similar to what UITableView will do table cells.

Apple has sample code that illustrates this technique in the ScrollView Suite sample project and Designing Apps videos with a scroll list from WWDC 2010.

+2
source

I also needed to set the UIView background from the image and resize it at the same time. I have done this:

  • The created image in the frame of my view size
  • Set the background view using [UIColor colorWithPatternImage:(UIImage*)]

And here is the code:

 UIGraphicsBeginImageContext(self.followView.frame.size); [[UIImage imageNamed:@"background_content.png"] drawInRect:self.followView.bounds]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIColor *bgColor = [UIColor colorWithPatternImage:image]; [followView setBackgroundColor:bgColor]; 
+3
source

Why not use a stretch image of one shelf, and then set it as a background for each cell in a table?

EDIT:

My knowledge of AQGridView limited, but it sounds like you can access each individual grid.

Try to have three images in a row: - Image for the left side of the grid to show the left corner of your shelf - Image for the center of the shelf that applies to all tiles except the first and last tiles - Image for the right side of the grid to show the right corner your shelf.

Also, you should probably mention that you are using AQGridView in your question so that other users do not think that you are using UITableView .

0
source

All Articles