// 畫邊框 (分為左半部分和右半部分,每次畫一部分)
-
(UIImage *)getEdgeLineImageWithType:(ELJSecondhandHomePageSceneFrameType)type {
NSInteger width = self.width;
NSInteger height = self.height;
NSInteger cornerRadius = 5;
NSInteger lineWidth = 1;
// 沿著邊框畫,會有一半的線寬畫到畫板外部,留出最小距離
CGFloat minSpace = lineWidth / 2.0;UIGraphicsBeginImageContextWithOptions(CGSizeMake(self.width, self.height), NO, [UIScreen mainScreen].scale);
CGContextRef context = UIGraphicsGetCurrentContext();
//設(shè)置顏色
UIColor *lineColor = [UIColor lj_colorWithHex:0xededed];
[lineColor set];
//畫線
CGMutablePathRef path = CGPathCreateMutable();
if (type == ELJSecondhandHomePageSceneFrameTypeLeft) { // 左側(cè)
CGPathMoveToPoint(path, NULL, width, minSpace);
CGPathAddLineToPoint(path, NULL, cornerRadius + minSpace, minSpace);
// 畫左上角圓角
CGPathAddArc(path, NULL, cornerRadius + minSpace, cornerRadius + minSpace, cornerRadius, M_PI_2 * 3, M_PI, true);
CGPathAddLineToPoint(path, NULL, minSpace, height - cornerRadius - minSpace);
// 畫左下角圓角
CGPathAddArc(path, NULL, cornerRadius + minSpace, height - cornerRadius - minSpace, cornerRadius, M_PI, M_PI_2, true);
CGPathAddLineToPoint(path, NULL, width, height - minSpace);
} else { // 右側(cè)
CGPathMoveToPoint(path, NULL, 0, minSpace);
CGPathAddLineToPoint(path, NULL, width - cornerRadius - minSpace, minSpace);
// 畫右上角圓角
CGPathAddArc(path, NULL, width - cornerRadius - minSpace, cornerRadius + minSpace, cornerRadius, M_PI_2 * 3, 0, false);
CGPathAddLineToPoint(path, NULL, width, height - cornerRadius - minSpace);
// 畫右下角圓角
CGPathAddArc(path, NULL, width - cornerRadius - minSpace, height - cornerRadius - minSpace, cornerRadius, 0, M_PI_2, false);
CGPathAddLineToPoint(path, NULL, 0, height - minSpace);
}CGContextSetLineWidth(context, lineWidth);
CGContextAddPath(context, path);
CGContextStrokePath(context);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CFRelease(path);
return image;
}