离屏渲染

1、圆角使用UIImageView装载一个圆角图片来处理。

@implementation UIImage (RoundedCorner) 

- (UIImage *)imageWithRoundedCornersAndSize:(CGSize)sizeToFit andCornerRadius:(CGFloat)radius

{

   CGRect rect = (CGRect){0.f, 0.f, sizeToFit};

   UIGraphicsBeginImageContextWithOptions(sizeToFit, NO, UIScreen.mainScreen.scale); CGContextAddPath(UIGraphicsGetCurrentContext(), [UIBezierPath bezierPathWithRoundedRect:re ct cornerRadius:radius].CGPath); CGContextClip(UIGraphicsGetCurrentContext()); [self drawInRect:rect]; UIImage *output = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext();

    [self drawInRect:rect];

   UIImage *output = UIGraphicsGetImageFromCurrentImageContext();

   UIGraphicsEndImageContext();

   return output;

}@end

2、设置阴影

  CALayer *shadowLayer = [CALayer layer];

  shadowLayer = [UIColor blackColor].CGColor;

  shadowLayer.shadowOpacity = 1.0;

  shadowLayer.shadowRadius = 4.0;

  shadowLayer.shadowOffset = CGSizeMake(4.0, 4.0); 

 以上可以使用shadowPath来解决,比如:
 shadowLayer.shadowPath = CGPathCreateWithRect(shadowLayer.bounds, NULL);
  开发过程中最好不要让view透明。
posted @ 2017-12-14 11:58  梦影随风  阅读(245)  评论(0编辑  收藏  举报