UIView 的 iPad 图层阴影效果

发布于 2024-11-16 01:31:16 字数 226 浏览 2 评论 0原文

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

单击此处查看 uiview 图像

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

提前致谢 乔.

I am trying to display a UIView similar to this image url

Click here to view uiview image

This is a UIView containing UIimageview and label.
Is there a way to set layer effect similar to this?

Thanks in advance
Joe.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几味少女 2024-11-23 01:31:16
#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;
}
#import <QuartzCore/QuartzCore.h>

you can use

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文