Tag: uibezierpath

在Objective-C中绘制起始和结束angular度的椭圆

我正在编写一个iPad应用程序,在该应用程序中,将呈现形状的XML对象呈现在屏幕上的graphics中。 我想渲染的对象之一是弧线。 基本上这些弧为我提供了一个边界矩形以及一个开始和结束angular度。 给定属性: X ÿ 宽度 高度 由startAngle endAngle 有了这些值,我需要绘制弧(其实质上是椭圆的一部分)。 我不能使用以下内容: UIBezierPath *arc = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(x, y, width, height)]; [UIColor blackColor] setStroke]; [arc stroke]; 因为它绘制了一个完整的椭圆。 基本上我需要上面的,但它需要考虑到开始和结束的angular度,所以只有一部分的椭圆显示。 我想这将涉及绘制一个三次贝塞尔曲线或二次贝塞尔曲线。 问题是我不知道如何计算我给出的信息的起点,终点或控制点。

如何在UIView中使用不同的颜色绘制多个UIBezierPath

我想在不同的笔触和填充颜色的uiview中绘制多个UIBezierPath。 这是代码 – (void)drawRect:(CGRect)rect { context = UIGraphicsGetCurrentContext(); [[UIColor grayColor] setFill]; [[UIColor greenColor] setStroke]; UIBezierPath *aPath = [[UIBezierPath alloc] init]; [aPath moveToPoint:CGPointMake(227,34.25)]; [aPath addLineToPoint:CGPointMake(298.25,34.75)]; [aPath addLineToPoint:CGPointMake(298.5,82.5)]; [aPath addLineToPoint:CGPointMake(251,83)]; [aPath addLineToPoint:CGPointMake(251,67.5)]; [aPath addLineToPoint:CGPointMake(227.25,66.75)]; [aPath closePath]; aPath.lineWidth = 2; [aPath fill]; [aPath stroke]; UIBezierPath* aPath2 = [[UIBezierPath alloc] init]; [aPath2 moveToPoint:CGPointMake(251.25,90.5)]; [aPath2 addLineToPoint:CGPointMake(250.75,83.25)]; [aPath2 addLineToPoint:CGPointMake(298.5,83)]; [aPath2 addLineToPoint:CGPointMake(298.5,90.25)]; […]

带颜色渐变的UIBezierPath

我有一个关于UIBezierPath的问题。 例如,我有这个path: 现在我想要从白色到红色的颜色渐变。 从左到右。 这是我的代码: UIBezierPath *bezierPath; bezierPath = [UIBezierPath bezierPathWithArcCenter:_center radius:_radius startAngle:((4 * angle)) endAngle:(((20) * angle)) clockwise:YES]; [bezierPath addLineToPoint:_center]; [bezierPath closePath]; UIColor *color = [UIColor colorWithHue:0/sectors saturation:1. brightness:1. alpha:1]; [color setFill]; [color setStroke]; [bezierPath fill]; [bezierPath stroke]; 谁能帮我? 编辑1: 我有这个色轮: UIBezierPath *bezierPath; for ( int i = 0; i < 360; i++) { […]

如何使用CAGradientLayer绘制渐变色轮?

我从这些链接中得到了一些参考 – 色轮背后的algorithm是什么? 色轮后面的math 基本的配色scheme 如何用渐变色填充贝塞尔path 我已经经历了“HSV色彩空间”的概念。 但是我想在CAGradientLayer的帮助下使用RGB绘制一个色轮。 这是通过使用简单的RGB颜色数组和UIBezierPath制作色轮的代码片段 – func drawColorWheel() { context?.saveGState() range = CGFloat(100.00 / CGFloat(colorArray.count)) for k in 0 ..< colorArray.count { drawSlice(startPercent: CGFloat(k) * range, endPercent: CGFloat(CGFloat(k + 1) * range), color: colorArray.object(at: k) as! UIColor) } context?.restoreGState() } func drawSlice(startPercent: CGFloat, endPercent: CGFloat, color: UIColor) { let startAngle = […]

iOS:UIBezierPath和CAShapeLayer fillRule

我之前使用过UIBezierPath和CAShapeLayer 。 但是几乎每次都要用里面的颜色填充path中包含的对象。 但是我希望这个时候能够填充UIBezierPath包含的对象之外的颜色。 我只写了下面的简单代码,试图让我熟悉fillRule属性: CAShapeLayer *myLayer = (CAShapeLayer*) self.layer; //size: 320 X 480 UIBezierPath *testPath = [UIBezierPath bezierPathWithOvalInRect:(CGRect){{100, 100}, 100, 100}]; //a simple circle myLayer.fillRule = kCAFillRuleNonZero; // have tried this as well: kCAFillRuleEvenOdd; myLayer.path = testPath.CGPath; myLayer.fillColor = [UIColor whiteColor].CGColor; 但是颜色仍然填充在里面。 我想知道的是,如何填补path外的颜色? 如果我在这里使用fillRule错误,我想知道是否有其他方法可以实现这一点。 提前致谢。

在视图中重新定位CGPath / UIBezierPath

是否有可能重新定位已经绘制的CGPath / UIBezierPath在视图上? 我想移动或改变一个path的位置,那么也许回想一下drawinRect方法再次显示绘图。

使用UIBezierPath:byRoundingCorners:使用Swift 2和Swift 3

我使用这个代码来使一个button的两个圆angular变圆。 let buttonPath = UIBezierPath(roundedRect: button.bounds, byRoundingCorners: UIRectCorner.TopLeft | UIRectCorner.BottomLeft, cornerRadii: CGSizeMake(1.0, 1.0)) 它会抛出一个错误: 二元运算符'|' 不能应用于两个UIRectCorner操作数。 如何在Swift 2.0中使用这个方法?

UIBezierPath绘制不同笔画的圆

基本上我需要有一个不同颜色的笔画,大小相等。 例如,1/2是蓝色,1/2是红色。 图片(对不起,这么糟糕的形象): 我怎样才能画出这样的东西?

UIBezierPath从图像

我有几个像这样的PNG文件: 一切都是透明的,但黑色的道路。 我想要做的是从非透明部分创build一个UIBezierPath。 编辑:所以我想着如何创build与PNG的面具然后从面具去UIBezierPath。 这会工作吗? 再次编辑:我find了解决scheme,看看我的答案。

UIBezierPath笔画1px线和填充1px宽的矩形 – 不同的结果。

这是一个简单的绘图 – (void)drawRect:(CGRect)rect { //vertical line with 1 px stroking UIBezierPath *vertLine = [[UIBezierPath alloc] init]; [vertLine moveToPoint:CGPointMake(20.0, 10.0)]; [vertLine addLineToPoint:CGPointMake(20.0, 400.0)]; vertLine.lineWidth = 1.0; [[UIColor blackColor] setStroke]; [vertLine stroke]; //vertical rectangle 1px width UIBezierPath *vertRect= [UIBezierPath bezierPathWithRect:CGRectMake(40.0, 10.0, 1.0, 390.0)]; [[UIColor blackColor] setFill]; [vertRect fill]; } 在非视网膜3GS和模拟器的第一行是模糊的,看起来比1像素宽,但第二行是脆。 不幸的是我没有iPhone4和新的iPadtesting,但在视网膜模拟器上,两条线看起来都是一样的。 问题:矩形而不是中风是获得非视网膜和视网膜设备相同结果的唯一方法?