2012-07-13 71 views
1

我有一个应用程序在那里我画我做了一个特殊的椭圆通过一系列贝塞尔路径如下:拉伸形状适合框架?

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSaveGState(context); 

CGMutablePathRef pPath_0 = CGPathCreateMutable(); 
CGPathMoveToPoint(pPath_0, NULL, 515.98,258.24); 
CGPathAddCurveToPoint(pPath_0, NULL, 515.98,435.61,415.54,515.98,258.24,515.98); 
CGPathAddCurveToPoint(pPath_0, NULL, 100.94,515.98,0.50,435.61,0.50,258.24); 
CGPathAddCurveToPoint(pPath_0, NULL, 0.50,80.86,100.94,0.50,258.24,0.50); 
CGPathAddCurveToPoint(pPath_0, NULL, 415.54,0.50,515.98,80.86,515.98,258.24); 
CGPathCloseSubpath(pPath_0); 
CGContextSetRGBFillColor(context, 1.0000, 1.0000, 1.0000, 1.0000); 

CGContextSetRGBStrokeColor(context,0.0000,0.0000,0.0000,1.0000); 
CGContextSetLineWidth(context, 1); 
CGContextSetMiterLimit(context, 10.0000); 

CGContextAddPath(context, pPath_0); 
CGContextDrawPath(context, kCGPathFillStroke); 
CGPathRelease(pPath_0); 
CGContextRestoreGState(context); 

我想知道,是否有核心图形的任何方式,我可以把我塑造只是在水平和垂直方向创建并拉伸,使其完美地适合其视图框架? IE浏览器,所以我不必手动进入所有的观点和价值观,并在视图边界上写下它们?我知道这个形状就不会是困难的,但我有一些更复杂的形状是耗费更多的时间,我宁愿避免这样做的..

+0

为什么试图编辑它以符合框架,如果您最初可以正确绘制它? – 2012-07-13 13:38:11

+0

尝试[Scale to Fill](http://stackoverflow.com/a/3401284/1059705)和[stretchableImageWithLeftCapWidth:topCapHeight](http://developer.apple.com/library/ios/#documentation/uikit/reference/ UIImage_Class/DeprecationAppendix/AppendixAdepledAPI.html#// apple_ref/occ/instm/UIImage/stretchableImageWithLeftCapWidth%3atopCapHeight%3a) – Bala 2012-07-13 13:39:12

+0

@teodorcarstea - 我有更多的形状比这更复杂,并有一吨贝塞尔路径,做起来容易。 – 2012-07-13 13:56:09

回答

0

找到了可以使用:

CGAffineTransform transform = CGAffineTransformMakeScale(frame.size.width/shapeWidth, frame.size.height/shapeHeight); 
CGMutablePathRef mutablePathTransform = CGPathCreateMutableCopyByTransformingPath(mutablePath, &transform);