iphone - 在 UIScrollView 中覆盖 drawRect 时的黑色背景

标签 iphone objective-c ios ipad

所以我试图在我的 UIScrolLView 中覆盖 drawRect,但是它给我这个黑色背景,而不是我为我的 UIScrollView 指定的背景颜色。为什么是这样?如果我删除 drawRect 代码,那么一切都很好:

- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    if (shouldDrawVerticalLineForProfile){

        CGContextRef context = UIGraphicsGetCurrentContext();
        CGColorRef separatorColor = [UIColor colorWithRed:47.0/255.0 green:47.0/255.0 
                                                     blue:47.0/255.0 alpha:1.0].CGColor;

        // Add at bottom
        CGPoint startPoint = CGPointMake(60, 0);
        CGPoint endPoint = CGPointMake(60, 10000);

        CGContextSaveGState(context);
        CGContextSetLineCap(context, kCGLineCapSquare);
        CGContextSetStrokeColorWithColor(context, separatorColor);
        CGContextSetLineWidth(context, 5.0);
        CGContextMoveToPoint(context, startPoint.x + 0.5, startPoint.y + 0.5);
        CGContextAddLineToPoint(context, endPoint.x + 0.5, endPoint.y + 0.5);
        CGContextStrokePath(context);
        CGContextRestoreGState(context);  

    }

}

最佳答案

我猜你要搜索的是:

myScrollViewInstance.opaque = NO

之后你的 ScrollView 的背景应该不再是黑色了。

关于iphone - 在 UIScrollView 中覆盖 drawRect 时的黑色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11318987/

相关文章:

iphone - 来自相机的 AVCaptureSession CVImageBufferRef 上的图层 OpenGL 内容

ios - "NSString stringWithFormat:"和 "%zd"在 32 位设备中的奇怪行为

ios - 在新 ViewController 中使用代码时发送到实例的 UIButton 无法识别的选择器

javascript - 如何在访问时在文本字段中获取和插入用户的电话号码

ios - 如何使用 nib 文件为 TableView 创建动态单元格

ios - 快速从服务器响应中获取值(value)

iphone - 我们可以将属性/合成到 sqlite3 * 数据库对象吗?

ios - NSNumber存储 float 。请没有科学记数法吗?

ios - 禁用单个 UIImageView 的自动布局

ios - 与另一个 UIView 共享 Nib 时如何初始化 UIView 子类