2010-07-08 83 views
0

我有一個UIScrollView,其中包含我想填充紋理的子視圖。如何在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); 
} 

這似乎填充滾動視圖的可見區域,當我滾動時,其餘是白色的。我如何在矩形的邊界之外畫一個矩形?那不好嗎?

回答

0

如果你想在這裏畫一個背景色太多了。 UIScrollView可以有背景顏色。這種顏色可以從一個圖像創建。

您可以創建一個圖案顏色

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

太好了,謝謝! – 2010-07-10 13:16:39