划线

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];

    CGContextRef drawCtr = UIGraphicsGetCurrentContext();
    CGContextSaveGState(drawCtr);
    CGMutablePathRef borderPath = CGPathCreateMutable();
    CGPathMoveToPoint(borderPath, NULL, 0, 0);
    
    float fh = self.fh;
    float ftop = self.ftop;
    float fl = self.fleft;
    float radius = self.radius;
    float fw = self.fw;

    CGPathMoveToPoint(borderPath, NULL, 0, 0);
    CGPathAddLineToPoint(borderPath, NULL, [self width], 0);
    CGPathAddLineToPoint(borderPath, NULL, [self width], ftop);
    CGPathAddLineToPoint(borderPath, NULL, 0, ftop);
    
    CGPathMoveToPoint(borderPath, NULL, 0, ftop);
    CGPathAddLineToPoint(borderPath, NULL, fl + radius, ftop);
    CGPathAddArcToPoint(borderPath, NULL, fl, ftop, fl, ftop + radius , radius);
    CGPathAddLineToPoint(borderPath, NULL, fl, ftop + fh - radius);
    CGPathAddArcToPoint(borderPath, NULL, fl , ftop + fh, fl + radius, fh + ftop, radius);
    CGPathAddLineToPoint(borderPath, NULL, 0, ftop + fh);

    CGPathMoveToPoint(borderPath, NULL, fw + fl - radius, ftop);
    CGPathAddArcToPoint(borderPath, NULL, fw + fl, ftop , fw + fl, ftop + radius, radius);
    CGPathAddLineToPoint(borderPath, NULL, fw + fl, ftop + fh - radius);
    
    CGPathAddArcToPoint(borderPath, NULL, fw + fl, fh + ftop, fl + fw - radius, ftop + fh, radius);
    CGPathAddLineToPoint(borderPath, NULL, [self width], ftop + fh);
    CGPathAddLineToPoint(borderPath, NULL, [self width], ftop);

    CGPathMoveToPoint(borderPath, NULL, 0, ftop + fh);
    CGPathAddLineToPoint(borderPath, NULL, [self width], ftop + fh);
    CGPathAddLineToPoint(borderPath, NULL, [self width], [self height]);
    CGPathAddLineToPoint(borderPath, NULL, 0, [self height]);
    
    CGContextAddPath(drawCtr, borderPath);
    [[UIColor colorWithRed:0 green:0 blue:0 alpha:0.7] setFill];
    CGContextDrawPath(drawCtr, kCGPathFill);
    CGPathRelease(borderPath);
    CGContextRestoreGState(drawCtr);
}

你可能感兴趣的:(划线)