
它与常规圆角矩形略有不同:
这是is readily available的准确公式.但是,我无法弄清楚如何使用CGPath,更不用说填写它,并且可以轻松地调整大小.所有这一切与公式完全一致.任何想法?
解决方法 来自维基百科: SuperellipseFor n = 1/2,in particular,each of the four arcs is a @H_301_12@Quadratic BézIEr curve defined by the two axes; as a result,each arc is a segment of a parabola.
那么为什么不试图用BezIEr曲线逼近Squircle?两个曲线(BezIEr和Squircle)都由参数方程定义.
UIBezierPath Class有方法:addCurvetoPoint:controlPoint1:controlPoint2:
Appends a cubic BézIEr curve to the receiver’s path.
注意:使用addQuadCurvetoPoint:controlPoint:方法使测试结果更差.
我使用这种方法,结果发生了什么事情:
红线 – 圆角矩形,蓝线 – 四边形BezIEr曲线的矩形
如果这个结果有兴趣 – 下面的绘图代码.
注意:要获得更精确的匹配,可以要求改变四角点的坐标(现在它们对应于其中刻有图形的矩形的角度)的贝塞尔曲线.
CGContextRef context = UIGraphicsGetCurrentContext();CGContextSaveGState(context);//set rect size for drawfloat rectSize = 275.;CGRect rectangle = CGRectMake(CGRectGetMIDX(rect) - rectSize/2,CGRectGetMIDY(rect) - rectSize/2,rectSize,rectSize);//Rounded rectangleCGContextSetstrokecolorWithcolor(context,[UIcolor redcolor].CGcolor);UIBezIErPath* roundedpath = [UIBezIErPath bezIErPathWithRoundedRect:rectangle cornerRadius:rectSize/4.7];[roundedpath stroke];//Rectangle from Fours BezIEr CurvesCGContextSetstrokecolorWithcolor(context,[UIcolor bluecolor].CGcolor);UIBezIErPath *bezIErCurvePath = [UIBezIErPath bezIErPath];//set coner pointsCGPoint topLPoint = CGPointMake(CGRectGetMinX(rectangle),CGRectGetMinY(rectangle));CGPoint topRPoint = CGPointMake(CGRectGetMaxX(rectangle),CGRectGetMinY(rectangle));CGPoint botLPoint = CGPointMake(CGRectGetMinX(rectangle),CGRectGetMaxY(rectangle));CGPoint botRPoint = CGPointMake(CGRectGetMaxX(rectangle),CGRectGetMaxY(rectangle));//set start-end pointsCGPoint mIDRPoint = CGPointMake(CGRectGetMaxX(rectangle),CGRectGetMIDY(rectangle));CGPoint botMPoint = CGPointMake(CGRectGetMIDX(rectangle),CGRectGetMaxY(rectangle));CGPoint topMPoint = CGPointMake(CGRectGetMIDX(rectangle),CGRectGetMinY(rectangle));CGPoint mIDLPoint = CGPointMake(CGRectGetMinX(rectangle),CGRectGetMIDY(rectangle));//Four BezIEr Curve[bezIErCurvePath movetoPoint:mIDLPoint];[bezIErCurvePath addCurvetoPoint:topMPoint controlPoint1:topLPoint controlPoint2:topLPoint];[bezIErCurvePath movetoPoint:mIDLPoint];[bezIErCurvePath addCurvetoPoint:botMPoint controlPoint1:botLPoint controlPoint2:botLPoint];[bezIErCurvePath movetoPoint:mIDRPoint];[bezIErCurvePath addCurvetoPoint:topMPoint controlPoint1:topRPoint controlPoint2:topRPoint];[bezIErCurvePath movetoPoint:mIDRPoint];[bezIErCurvePath addCurvetoPoint:botMPoint controlPoint1:botRPoint controlPoint2:botRPoint];[bezIErCurvePath stroke];CGContextRestoreGState(context);总结
以上是内存溢出为你收集整理的以程序方式绘制iOS 7风格的圆形全部内容,希望文章能够帮你解决以程序方式绘制iOS 7风格的圆形所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)