Create rectangle in iOS Objective C with and without fill

Solution:

In iOS you can create a rectangle using CGContextref.The below code is used for draw a rectangle in a view with 0 x axis,0 y axis,width 20 and height 20..



    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGRect rect = CGRectMake(0, 0,20,20)
    CGContextClearRect(ctx, rect);
    CGContextSetLineWidth(ctx, self.layerWidth);
    CGPathRef path = CGPathCreateWithRect(self.bounds, NULL);
    CGContextAddPath(ctx, path);

    CGContextDrawPath(ctx, kCGPathFillStroke);

If you want to fill the rectangle then add the below code 

        CGContextSetStrokeColorWithColor(ctx, color.CGColor);

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift