iOS: Create one sideded dropshadow

前端 未结 3 918
小鲜肉
小鲜肉 2021-02-04 15:20

I have the below menu style layout that mimics facebook. I would like to have a dropshadow on the left side like below however the code I am using with layer shadows makes the a

相关标签:
3条回答
  • 2021-02-04 15:33

    You can just inset the views bounds and set the shadow path:

    UIEdgeInsets contentInsets = UIEdgeInsetsMake(10, 0, 0, 0);
    CGRect shadowPathExcludingTop = UIEdgeInsetsInsetRect(self.bounds, contentInsets);
    self.layer.shadowPath = [UIBezierPath bezierPathWithRect:shadowPathExcludingTop].CGPath;
    
    0 讨论(0)
  • 2021-02-04 15:38

    I for myself would just add a UIView containing that shadow as a subview and reposition it as soon as the view on the right side is animated. (e.g. draw that shadow with layers or core graphics)

    0 讨论(0)
  • 2021-02-04 15:47

    It should help to specify a shadow path, e.g.,

    CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:self.navController.view.layer.bounds].CGPath;
    [self.navController.view.layer setShadowPath:shadowPath]
    

    According to the CALayer documentation, "Specifying an explicit path usually improves rendering performance."

    0 讨论(0)
提交回复
热议问题