xexe
xexe

Reputation: 346

resizableImageWithCapInsets in iOS 4

I need to create table cells with a very complicated background image for each: https://i.sstatic.net/PBL0S.png

There is a transparent circle in the center of it. And height of my cell depends from its content - it may vary. But I need this circle to always be in the center of background image and have a constant size.

My solution is: cut the image along for 2 parts and then, using the method resizableImageWithCapInsets: create two UIImageView's and locate them one below the other. There is the problem: this method is only availible since iOS 5, but my app needs to run under iOS 4.3. Unfortunatelly, I can't use method stretchableImageWithLeftCapWidth:topCapHeight: because top and bottom caps on my half-images obtained with different heights.

Please, help me to create the method with the same functionality resizableImageWithCapInsets: Or, if there is any better solution, tell it to me, please.

Upvotes: 0

Views: 369

Answers (1)

Engin Kurutepe
Engin Kurutepe

Reputation: 6747

The straight-forward approach can involve three imageviews:

  • top imageview: stretchable image with the top part of your tag image
  • center imageview: non-stretchable fixed size image with the center part of your tag image including the white hole
  • bottom imageview: stretchable image with the bottom part of your tag image

subclass UITableViewCell and override layoutSubviews such that the top image view are always the same size and the center image view preserves its size and center position.

EDIT:

You can also use the stretchableImageWithLeftCapWidth:topCapHeight: method with different cap heights for different images. I don't see a reason why your approach should not work as well.

Upvotes: 2

Related Questions