【问题标题】:Siri chat bubble color's in iOSiOS 中的 Siri 聊天气泡颜色
【发布时间】:2011-11-04 14:12:10
【问题描述】:

我尝试在核心图形中创建 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);

}

【问题讨论】:

  • 图片是你代码输出的上方,还是你想要实现的 Siri 截图?
  • 我已经添加了我的输出。这是第二张图片..

标签: iphone ios uiimageview quartz-graphics siri


【解决方案1】:

填充颜色主要是白色,不透明度约为 10%。所以原来的背景(类似织物的图案)会透出来,变得稍微亮一些。边框颜色也是白色,但不透明度约为 30%。

另外,边框的右侧和底部有轻微的阴影。

对于颜色,您大约需要:

CGContextSaveGState(context);
CGContextSetShadow(context, CGSizeMake(-15f, -20f), 1.0f);
CGContextSetLineWidth(context, 2.0f);
CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 0.1f);
CGContextFillPath(context);
CGContextRestoreGState(context);

CGContextSetRGBStrokeColor(context, 1.0f, 1.0f, 1.0f, 0.3f);
CGContextStrokePath(context);

【讨论】:

  • 如何在代码中应用边框颜色和填充颜色。如果我设置它,则只设置borderColor或填充颜色中的一种,而忽略另一种。
  • @Jacob:还有一个阴影效果的更新。但我对正确参数没有太多经验。
  • @codo.. 不走运 :(.. 我只得到填充颜色.. 我也改成 CGContextDrawPath(context, kCGPathStroke);
  • @Jacob:我的代码确实有错误。但它是 CGContextStrokePath(context) 而不是 CGContextDrawPath(context, kCGPathStroke)。
  • Quartz 不是一个简单的 API,可以在一个下午轻松掌握。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-31
  • 2012-07-31
  • 2021-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-01
相关资源
最近更新 更多