畫三條邊 的 邊框與圓角

// 畫邊框 (分為左半部分和右半部分,每次畫一部分)

  • (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;
    }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容