【发布时间】:2012-06-23 13:05:30
【问题描述】:
我正在使用一个名为 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);
【问题讨论】:
-
假设我用它的自定义 drawRect 调用我的自定义视图(如上) UICustomView *myView = [[UICustomView alloc] initWithFrame:CGRectMake(200, 70, 80,30)];它的框架是正确的,但是在 drawRect 中绘制的结果对于框架来说太大了。如何使 drawRect 将上下文调整为给定矩形的大小。
-
我试过 CGContextTranslateCTM(context, rect.size.width, rect.size.height); CGContextScaleCTM(上下文, 1.0, -1.0);例如
-
还要补充一点,生成的 drawRect 非常大,有许多路径,因此无法更改硬编码坐标。