我正在使用一个名为Quarkee的应用程序将徽标从SVG转换为Quartz 2d代码,这是一种享受。唯一的问题是我似乎无法弄清楚如何调整结果的大小。如果我设置 UIView 的框架,drawRect 的结果在框架中保持很大。如何让它达到我正在设置的框架的大小?
下面是一个示例。
有人可以帮忙吗?
- (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);
这里的解决方案是使用 view.transform = CGAffineTransformMakeScale(0.5f, 0.5f); 来调整视图大小
看看这些值:
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);
调用 drawRect
方法时,可以使用 self.bounds
获取视图的当前矩形,并根据它调整这些值。您说您已经从应用程序生成了此代码 - 这些应用程序通常会在生成代码时对绘制的图形的大小进行硬编码,因此您必须查看这些值与您绘制的图像的实际大小之间的关系,并根据self.bounds
大小使它们动态......