0

I would like to obtain a UIView like this :

Screenshot

But i don't know, what is the best way to do this ?

Is this the best way: https://stackoverflow.com/a/9214570/1228634 ?

Community
  • 1
  • 1
Royal
  • 23
  • 1
  • 6

2 Answers2

3

Create the shadow as a transparent layer at a particular size, also create a stretchable image, like this:

UIImage *shadowImage = [UIImage imageNamed:@"shadow.png"];
shadowImage = [shadowImage stretchableImageWithLeftCapWidth:floorf(shadowImage.size.width/2) topCapHeight:floorf(shadowImage.size.height/2)];

Put the image in a UIImageView with contentMode as scale to fit.

Call your view as "sView". You can add the shadow like this:

UIImageView *shadowImgView = [[UIImageView alloc] initWithImage:shadowImage];
shadowImgView.contentMode = UIViewContentModeScaleToFill;
shadowImgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
shadowImgView.frame = sView.bounds;
[sView shadowImgView];
[shadowImgView release]; // only needed if you aren't using ARC
nithin
  • 2,457
  • 1
  • 30
  • 50
0

You can try to use several pictures (as it works for html), but I don't think it is better than your example:

  • you need 4 small pictures to make a texture for top, left, right and bottom border
  • you need 4 pictures for your View's corners;
  • draw to make a border from first 4 images using repeating;
  • draw corner images.
Gargo
  • 704
  • 6
  • 16