离屏渲染

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

@implementation UIImage (RoundedCorner) blog

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

{ip

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

   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];it

   UIImage *output = UIGraphicsGetImageFromCurrentImageContext();io

   UIGraphicsEndImageContext();class

   return output;im

}@end

二、设置阴影

  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透明。