绘制矩形

-(void)drawRect:(CGRect)rect{

CGContextRefcontext =UIGraphicsGetCurrentContext();

CGRectframeSize =self.bounds;

CGContextMoveToPoint(context,0,0);//起始点

CGContextAddLineToPoint(context, frameSize.size.width/2+30,0);//上平行线

CGContextAddLineToPoint(context, frameSize.size.width/2, frameSize.size.height);//右斜线

CGContextAddLineToPoint(context,0, frameSize.size.height);//下平行线

CGContextClosePath(context);//收拢, 做成直角梯形

[[UIColorredColor]setFill];

CGContextSetShadow(context,CGSizeMake(4,3),5);

CGContextDrawPath(context,kCGPathFill);

CGContextMoveToPoint(context, frameSize.size.width/2+30,0);//起始点

CGContextAddLineToPoint(context, frameSize.size.width,0);//上平行线

CGContextAddLineToPoint(context, frameSize.size.width, frameSize.size.height);//右斜线

CGContextAddLineToPoint(context, frameSize.size.width/2, frameSize.size.height);//下平行线

CGContextClosePath(context);//收拢, 做成直角梯形

[[UIColorcyanColor]setFill];

CGContextSetShadow(context,CGSizeMake(4,3),5);

CGContextDrawPath(context,kCGPathFill);

}

你可能感兴趣的:(绘制矩形)