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);