Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在UIScrollView中绘制大背景?_Iphone_Quartz 2d - Fatal编程技术网

Iphone 如何在UIScrollView中绘制大背景?

Iphone 如何在UIScrollView中绘制大背景?,iphone,quartz-2d,Iphone,Quartz 2d,我有一个UIScrollView,其中包含一个子视图,我想用纹理填充它 - (void)drawRect:(CGRect)rect { CGImageRef image_to_tile_ret_ref = CGImageRetain(wood.CGImage); CGRect tile_rect; tile_rect.size = wood.size; CGContextRef context = UIGraphicsGetCurrentContext();

我有一个
UIScrollView
,其中包含一个子视图,我想用纹理填充它

- (void)drawRect:(CGRect)rect {

    CGImageRef image_to_tile_ret_ref = CGImageRetain(wood.CGImage);
    CGRect tile_rect;
    tile_rect.size = wood.size;

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);
    CGContextMoveToPoint(context, 0, 0);
    CGContextDrawTiledImage(context, tile_rect, image_to_tile_ret_ref);
// Something here to make it fill a big area
    CGContextFillPath(context);

    CGImageRelease(image_to_tile_ret_ref);
}

这似乎只是填充了滚动视图的可见区域,当我滚动时,其余部分是白色的。如何在矩形的边界之外绘制矩形?那么糟糕吗

如果您想在中绘制背景色,这太多了。UIScrollView可以有背景色。该颜色可以从作为图像的图案创建

可以创建图案颜色

UIColor * bgColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imgname.png"]];
scrollView.backgroundColor = bgColor;