Using CGRect and CGContext to Create ImageView for Signature Box

200 views Asked by At

I create an image view for an app that I have the user use as a signature box. Right now I'm using the following code to create this "box".

imageFrame                = CGRectMake(self.view.center.x/2,
                            self.view.center.y/2,
                            self.view.frame.size.width/2,
                            self.view.frame.size.height/4);

I want to make that same rectangle using this code: basically a white box that has a signature box (an x and solid line for people to sign)

if I replace the code with this:

imageframe =
CGContextRef context = UIGraphicsGetCurrentContext();  
 CGContextConcatCTM(context, (CGAffineTransform){.a=1.0,.b=0.0,.c=0.0,.d=-1.0,.tx=0.0,.ty=480.0,});
// rect_canvas_background 
 CGContextMoveToPoint(context,-1.0f,-1.0f);
 CGContextAddLineToPoint(context,641.0f,-1.0f);
 CGContextAddLineToPoint(context,641.0f,481.0f);
 CGContextAddLineToPoint(context,-1.0f,481.0f);
 CGContextClosePath(context);
 CGContextSetRGBFillColor(context,1.0f,1.0f,1.0f,1.0f);
 CGContextEOFillPath(context);

I get multiple errors regarding all of the CGContext lines. I'm assuming I'm missing something simple with the way these things are done within iOS but I can't figure out what it is. Any help would be appreciated.

1

There are 1 answers

0
Satyaranjan On

As far as I'm concerned,

 CGContextConcatCTM(context, (CGAffineTransform){.a=1.0,.b=0.0,.c=0.0,.d=-1.0,.tx=0.0,.ty=480.0,});

contains variables preceding with '.'

Try by passing the values only. No variable assignment is required I guess.

If you get success, then let me know as well.