2012-03-15 15 views
2

UIScrollViewにグラデーションの背景を追加するには?私はそれの上にUIScrollViewとviewcontrollerを持っています。私は、スクロールビューにグラデーションの背景を追加したい。私は背景のグラデーションイメージも持っていますが、スクロールビューのコンテンツサイズに完全には合っていません。グラデーションの背景UIScrollView

助けてください。 ありがとう

答えて

8

私は以前、UIScrollViewbackgroundColorをクリアし、スクロールビューの後ろにグラディエントビューを配置するように設定しました。私が持っているでしょうUIScrollView年代drawRectに直接グラデーションを描画するどのような効果がわからない

- (void)drawRect:(CGRect)rect 
{ 
    CGContextRef currentContext = UIGraphicsGetCurrentContext(); 

    CGGradientRef glossGradient; 
    CGColorSpaceRef rgbColorspace; 
    size_t num_locations = 2; 
    CGFloat locations[2] = { 0.0, 1.0 }; 
    CGFloat components[8] = { 0.119, 0.164, 0.192, 1.000, // Start color 
     0.286, 0.300, 0.307, 1.000 }; // End color 

    rgbColorspace = CGColorSpaceCreateDeviceRGB(); 
    glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations); 

    CGRect currentBounds = self.bounds; 
    CGPoint topCenter = CGPointMake(CGRectGetMidX(currentBounds), 0.0f); 
    CGPoint midCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMaxY(currentBounds)); 
    CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, midCenter, 0); 

    CGGradientRelease(glossGradient); 
    CGColorSpaceRelease(rgbColorspace); 
} 

:次にようにそのUIViewにグラデーションを描きます。

関連する問題