一、圓角使用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);