我想获得这样的UIView
:
但是我不知道,最好的方法是什么?
这是最好的方法:https://stackoverflow.com/a/9214570/1228634吗?
最佳答案
将阴影创建为特定大小的透明层,还创建可拉伸的图像,如下所示:
UIImage *shadowImage = [UIImage imageNamed:@"shadow.png"];
shadowImage = [shadowImage stretchableImageWithLeftCapWidth:floorf(shadowImage.size.width/2) topCapHeight:floorf(shadowImage.size.height/2)];
将图像放在带有contentMode作为缩放比例的UIImageView中。
将您的视图称为“ sView”。您可以像这样添加阴影:
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
关于iphone - UIView创建一个内部阴影,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9783523/