UIView 的 iPad 图层阴影效果

Posted

技术标签:

【中文标题】UIView 的 iPad 图层阴影效果【英文标题】:iPad layer shadow effect for UIView 【发布时间】:2011-06-15 12:01:15 【问题描述】:

我正在尝试显示类似于此图像 url 的 UIView

Click here to view uiview image

这是一个包含 UIimageview 和标签的 UIView。 有没有办法设置类似这样的图层效果?

提前致谢 乔。

【问题讨论】:

【参考方案1】:
#import <QuartzCore/QuartzCore.h>

你可以使用

imageView.layer.shadowRadius = 2.0;
imageView.layer.shadowOpacity = 0.7;
imageView.layer.shadowColor = [UIColor blackColor].CGColor;
imageView.layer.shadowPath = [self createArcShadowPathForRect:imageView.frame].CGPath

#define archeight 25

-(UIBezierPath *)createArcShadowPathForRect:(CGRect)rect 

    CGFloat h_padding =  (self.imageView.frame.size.width - rect.size.width) /2;
    CGFloat v_padding =  (self.imageView.frame.size.height - rect.size.height) /2-10;

    CGPoint startPoint =        CGPointMake(0 + h_padding, rect.size.height + v_padding) ;
    CGPoint pointTwo =          CGPointMake(0 + h_padding, rect.size.height + archeight + v_padding) ;
    CGPoint controlCenterPoint =   CGPointMake(rect.size.width/2 + h_padding, rect.size.height + v_padding+ 10);
    CGPoint leftDownPoint =     CGPointMake(rect.size.width + h_padding, rect.size.height + archeight + v_padding) ;
    CGPoint leftUpPoint =       CGPointMake(rect.size.width + h_padding, rect.size.height + v_padding) ;

    UIBezierPath *path = nil;
    if(!path) 
        path = [[UIBezierPath bezierPath] retain];
        [path moveToPoint:startPoint];
        [path moveToPoint:pointTwo];        
        [path addQuadCurveToPoint:leftDownPoint controlPoint:controlCenterPoint];
        [path addLineToPoint:leftUpPoint];
        [path addLineToPoint:startPoint];
        [path closePath];

    
    return path;

【讨论】:

以上是关于UIView 的 iPad 图层阴影效果的主要内容,如果未能解决你的问题,请参考以下文章

谁知道photoshop中怎么使图片产生阴影效果

UIView层的内阴影效果?

怎么用CSS做图层的投影效果?

ps如何设置阴影

在视图大小更改时更改 UIView 阴影大小会产生奇怪的效果

UIView 图层阴影在旋转后变暗