美文网首页
IOS 同时设置 圆角阴影

IOS 同时设置 圆角阴影

作者: pyboy | 来源:发表于2017-07-18 10:55 被阅读180次

项目提到一个新需求,把UIImageView切成圆角图标的同时,加上阴影。如下图:

实现方式:

// 头像
    UIImageView* head = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, headRadius * 2, headRadius * 2)];
    // 圆角图片
    [head sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", appImgUrl]] placeholderImage:[UIImage imageNamed:@"xjp.png"]];
    //设置边框的宽度
    head.layer.borderWidth = 1;
    //设置边框颜色
    head.layer.borderColor = [[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5]CGColor];
    head.layer.masksToBounds = YES;
    head.layer.cornerRadius = headRadius;
 UIView *shadowView = [[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width / 2 - headRadius, height, headRadius * 2, headRadius * 2)];
    shadowView.layer.shadowColor = [UIColor blackColor].CGColor;
    shadowView.layer.shadowOffset = CGSizeMake(0, 0);
    shadowView.layer.shadowOpacity = 1;
    shadowView.layer.shadowRadius = 5.0;
    shadowView.layer.cornerRadius = 5.0;
    shadowView.clipsToBounds = NO;
    [shadowView addSubview:head];
    [content addSubview:shadowView];
clipsToBounds
是指视图上的子视图,如果超出父视图的部分就截取掉,
masksToBounds
却是指视图的图层上的子图层,如果超出父图层的部分就截取掉

相关文章

网友评论

      本文标题:IOS 同时设置 圆角阴影

      本文链接:https://www.haomeiwen.com/subject/kybckxtx.html