ios - 边框重叠的矩形

标签 ios cgrectmake

当我尝试绘制彼此重叠的矩形时,我遇到了一个奇怪的问题。 见下图:

enter image description here

正如您所看到的,顶线比其他线(底部线和垂直线)更清晰,特别是比分隔矩形的线更清晰。 我使用了以下代码:

for (int i = 0; i < 7; i++)
{

    (...)
    CGContextBeginPath(context);
    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
    CGContextSetLineWidth(context, self.cellBorder);
    CGRect dayRect;
    if (i > 0)
        dayRect   = CGRectMake(i*cellWidth+self.marginX - 1, 0, cellWidth, cellHeight);
    else
        dayRect   = CGRectMake(i*cellWidth+self.marginX , 0, cellWidth, cellHeight);
    CGContextStrokeRect(context, dayRect);

}

有什么建议吗?

最佳答案

顶线比其他线细的原因是您的 self.cellBorder 线粗大于 0,并且您将其绘制在 y = 的线上0 。执行此操作时,您只会看到线条粗细的一半,因为另一半位于绘图矩形上方。要解决此问题,您只需在 y 位置 self.cellBorder/2 处绘制顶线即可。以下是代码的更改方式:

for (int i = 0; i < 7; i++) {
    // ...
    CGContextBeginPath(context);
    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
    CGContextSetLineWidth(context, self.cellBorder);
    CGRect dayRect;
    if (i > 0)
        dayRect = CGRectMake(i*cellWidth+self.marginX - 1, self.cellBorder / 2, cellWidth, cellHeight);
    else
        dayRect = CGRectMake(i*cellWidth+self.marginX , self.cellBorder / 2, cellWidth, cellHeight);
    CGContextStrokeRect(context, dayRect);
}

关于ios - 边框重叠的矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18701088/

相关文章:

ios - AVPlayer 失败后不会播放新的 AVPlayerItem

ios - UIBarButton 不会显示在我的 UINavigationController 中

ios - UIToolbar 和 CGRectMake

ios - 更改 UIView 框架

ios - 自定义UIView大小位置和IBaction

ios - 检查 getter 中的 CGRect 是否为 null

ios - 我怎样才能在 ruby​​ 中实现这个 objC 代码

iOS7 崩溃 - PopViewController 在 Landscape ViewController 上调用

objective-c - CGRect制作替代品

iphone - 如何处理通讯录变更