I would like create an inner shadow on my UIView
on iPad like that :
This UIView
could change size so I can't use a simple image to create this kind of shadow.
I have tested with setShadow
etc., but it's only a dropshadow that is created.
Any idea how to create this kind of shadow?
You may find it useful, I made an UIView Category for that
https://github.com/Seitk/UIView-Shadow-Maker
Create the shadow as a transparent layer at a particular size, then 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)];
You can then put that as the image in a UIImageView with contentMode scale to fit and it will work the way you want.
Lets say your view is called "myView". You can add the shadow like this:
UIImageView *shadowImageView = [[UIImageView alloc] initWithImage:shadowImage];
shadowImageView.contentMode = UIViewContentModeScaleToFill;
shadowImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
shadowImageView.frame = myView.bounds;
[myView addSubview:shadowImageView];
[shadowImageView release]; // only needed if you aren't using ARC
You can also do most of this in interface builder if you prefer, as long as you create the stretchable image itself in code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With