0

I'm using an app called Quarkee to convert a logo from SVG to Quartz 2d code, which works a treat. Only problem is I can't seem to figure out how resize the result. If I set the frame of the UIView, the result from drawRect stays huge in the frame. How do I get it be the size of the frame I'm setting?

An example of the out is below.

Can someone help?

- (void)drawRect:(CGRect)rect
{

CGContextRef context = UIGraphicsGetCurrentContext();
CGColorSpaceRef colorspace_1 = CGColorSpaceCreateDeviceRGB();
CGFloat components_1[] = {0.9961,0.9961,0.9961, 1.0000};
CGColorRef color_1 = CGColorCreate(colorspace_1, components_1);
CGContextSetFillColorWithColor(context,color_1);

CGContextMoveToPoint(context, 0.4960,0.1090);
CGContextAddLineToPoint(context,662.9260,0.1090);
CGContextAddLineToPoint(context,662.9260,227.8780);
CGContextAddLineToPoint(context,0.4960,227.8780);
CGContextAddLineToPoint(context,0.4960,0.1090);
CGContextClosePath(context);


CGContextFillPath(context);
BigBadOwl
  • 669
  • 2
  • 9
  • 22
  • Say I call my custom view with it's custom drawRect (as above) UICustomView *myView = [[UICustomView alloc] initWithFrame:CGRectMake(200, 70, 80,30)]; it's frame is correct, but the result drawn in drawRect is too large for the frame. How do I make the drawRect resize the context to the size of the given rect. – BigBadOwl Jun 23 '12 at 15:11
  • I have tried CGContextTranslateCTM(context, rect.size.width, rect.size.height); CGContextScaleCTM(context, 1.0, -1.0); for example – BigBadOwl Jun 23 '12 at 15:14
  • Also to add, the resulting drawRect is HUGE with many many paths, making it infeasible to alter the hard coded coordinates. – BigBadOwl Jun 23 '12 at 16:00

2 Answers2

1

The solution here was to use view.transform = CGAffineTransformMakeScale(0.5f, 0.5f); to resize the view

BigBadOwl
  • 669
  • 2
  • 9
  • 22
0

Take a look at these values:

CGContextMoveToPoint(context, 0.4960,0.1090);
CGContextAddLineToPoint(context,662.9260,0.1090);
CGContextAddLineToPoint(context,662.9260,227.8780);
CGContextAddLineToPoint(context,0.4960,227.8780);
CGContextAddLineToPoint(context,0.4960,0.1090);

when the drawRect method is called you can use self.bounds to take the current rect of your view and adjust those values according to it. You say you have generated this code from a application - those apps usually hardcode the size of the graphics you have drawn, when generate code, so you must see what is the relation between these values with the actual size of the image you have drawn and make them dynamic according to the self.bounds size...

graver
  • 15,183
  • 4
  • 46
  • 62
  • Thanks graver. The drawRect in this situation is drawing a whole logo with hundreds of lines of code into the context and your correct, the points are hard coded, making it infeasible to rewrite them to the bounds of the supplied rect. – BigBadOwl Jun 23 '12 at 16:02