我正在使用名爲Quarkee的應用程序將標誌從SVG轉換爲Quartz 2d代碼,該代碼可以工作。唯一的問題是我似乎無法弄清楚如何調整結果。如果我設置了UIView的框架,drawRect的結果在框架中保持很大。我如何得到它是我設置的框架的大小?IOS Quartz 2D drawRect and Resizing
下面是一個例子。
有人可以幫忙嗎?
- (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將上下文的大小調整爲給定矩形的大小。 – BigBadOwl
我試過CGContextTranslateCTM(context,rect.size.width,rect.size.height); CGContextScaleCTM(context,1.0,-1.0);例如 – BigBadOwl
也要添加,得到的drawRect是巨大的,有許多路徑,使得改變硬編碼座標變得不可行。 – BigBadOwl