Я пытался создать пузырь чата Siri в основной графике.Я нахожусь на этапе, когда я могу нарисовать форму.Я застрял с цветом здесь.Wanaa получить цвет границы и цветовой код заливки.вот что я сделал до сих пор ..
- (void)drawInContext:(CGContextRef)context
{
CGRect rect = gradientRectFrame;
CGFloat radius = 30;
CGFloat originBufferX = 0.0;
CGFloat originBufferY = 0.0;
CGFloat rightAngleTriangleWidth = 20.0;
CGFloat rightAngleTriangleHeight = 20.0;
CGFloat fullRectWidth = rect.size.width;
CGFloat fullRectHeight = rect.size.height;
CGPoint pointZero = CGPointMake(originBufferX, fullRectHeight);
CGPoint pointOne = CGPointMake(originBufferX + rightAngleTriangleWidth, fullRectHeight - rightAngleTriangleHeight);
CGPoint pointTwo = CGPointMake(originBufferX + rightAngleTriangleWidth, radius + originBufferY);
CGPoint pointThree = CGPointMake(originBufferX + fullRectWidth - radius, 0 + originBufferY);
CGPoint pointFour = CGPointMake(fullRectWidth, originBufferY + fullRectHeight - radius);
CGContextSetRGBFillColor(context, 105/255, 105/255, 105/255, 0.5);
CGContextSetLineWidth(context, 2.0);
CGContextMoveToPoint(context, pointZero.x, pointZero.y);
CGContextAddLineToPoint(context, pointOne.x, pointOne.y);
CGContextAddLineToPoint(context, pointTwo.x, pointTwo.y);
CGContextAddArc(context, rightAngleTriangleWidth + radius, originBufferY + radius, radius, M_PI, -M_PI_2, 0);
CGContextAddLineToPoint(context, pointThree.x, pointThree.y);
CGContextAddArc(context, fullRectWidth - radius, originBufferY + radius, radius, -M_PI_2, 0.0f, 0);
CGContextAddLineToPoint(context, pointFour.x, pointFour.y);
CGContextAddArc(context, fullRectWidth - radius, originBufferY + fullRectHeight - radius, radius, 0.0f, M_PI_2, 0);
CGContextAddLineToPoint(context, pointZero.x, pointZero.y);
CGContextFillPath(context);
CGContextSetRGBStrokeColor(context, 50/255, 50/255, 50/255, 0.5);
// CGContextSetRGBStrokeColor (context, 1.0, 0.0, 0.0, 1.0);
CGContextStrokePath(context);
}
Обновленный код: теперь я использую CGPath вместо CGContenxt, чтобы перерисовать мой путь после того, как я заполню свой путь.Вот новый код.Хотя мой цвет обводки еще не совсем близок ..
- (void)drawInContext:(CGContextRef)context
{
CGRect rect = gradientRectFrame;
CGFloat radius = 20;
CGFloat originBufferX = 0.0;
CGFloat originBufferY = 0.0;
CGFloat rightAngleTriangleWidth = 20.0;
CGFloat rightAngleTriangleHeight = 20.0;
CGFloat fullRectWidth = rect.size.width;
CGFloat fullRectHeight = rect.size.height;
CGPoint pointZero = CGPointMake(originBufferX, fullRectHeight);
CGPoint pointOne = CGPointMake(originBufferX + rightAngleTriangleWidth, fullRectHeight - rightAngleTriangleHeight);
CGPoint pointTwo = CGPointMake(originBufferX + rightAngleTriangleWidth, radius + originBufferY);
CGPoint pointThree = CGPointMake(originBufferX + fullRectWidth - radius, 0 + originBufferY);
CGPoint pointFour = CGPointMake(fullRectWidth, originBufferY + fullRectHeight - radius);
CGContextSetRGBStrokeColor(context, 0.8, 0.8, 0.8, 0.3);
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, pointZero.x, pointZero.y);
CGPathAddLineToPoint(path, NULL, pointOne.x, pointOne.y);
CGPathAddLineToPoint(path, NULL, pointTwo.x, pointTwo.y);
CGPathAddArc(path, NULL, rightAngleTriangleWidth + radius, originBufferY + radius, radius, M_PI, -M_PI_2, 0);
CGPathAddLineToPoint(path, NULL, pointThree.x, pointThree.y);
CGPathAddArc(path, NULL, fullRectWidth - radius, originBufferY + radius, radius, -M_PI_2, 0.0f, 0);
CGPathAddLineToPoint(path, NULL, pointFour.x, pointFour.y);
CGPathAddArc(path, NULL, fullRectWidth - radius, originBufferY + fullRectHeight - radius, radius, 0.0f, M_PI_2, 0);
CGPathAddLineToPoint(path, NULL, pointZero.x, pointZero.y);
CGContextSaveGState(context);
CGContextAddPath(context, path);
CGContextSetLineWidth(context, 2.0f);
CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 0.1f);
CGContextFillPath(context);
CGContextAddPath(context, path);
CGContextStrokePath(context);
}