BigBadOwl
BigBadOwl

Reputation: 678

IOS Quartz 2D drawRect and Resizing

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);

Upvotes: 0

Views: 608

Answers (2)

BigBadOwl
BigBadOwl

Reputation: 678

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

Upvotes: 1

graver
graver

Reputation: 15213

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...

Upvotes: 0

Related Questions