2011-12-28 3 views
0

tableViewを背景ビュー(グラデーション)で塗りつぶしましたが、残念ながら背景の半分だけが塗りつぶされていました。UITableViewの背景が半分しか塗りつぶされていませんか?

どのように後半を埋めるためのアイデア?

事前に大きな感謝!

コード:

UIView* myView = [[GradientBackground alloc] initWithFrame:CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, self.view.bounds.size.height)]; 

myTableView.backgroundColor = [UIColor clearColor]; 

myTableView.backgroundView = myView; 

Gradientbackground.m

- (id)initWithFrame:(CGRect)frame 
{ 
self = [super initWithFrame:frame]; 
if (self) { 
    // Initialization code 
} 
return self; 
} 

- (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] = { 25.0/255.0, 89.0/255.0, 140.0/255.0, 0.65, // Start color 
25.0/255.0, 89.0/255.0, 140.0/255.0, 1.0 }; // End color 


//(25.0/255.0) green:(89.0/255.0) blue:(140.0/255.0) 

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), CGRectGetMidY(currentBounds)); 
CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, midCenter, 0); 

CGGradientRelease(glossGradient); 
CGColorSpaceRelease(rgbColorspace); 
} 

25.0/255.0, 89.0/255.0, 140.0/255.0, 1.0 }; // End color 


//(25.0/255.0) green:(89.0/255.0) blue:(140.0/255.0) 

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), CGRectGetMidY(currentBounds)); 
CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, midCenter, 0); 

CGGradientRelease(glossGradient); 
CGColorSpaceRelease(rgbColorspace); 

enter image description here

答えて

1

グラデーションのコードが間違っていました。私はビューの中央を使用しましたが、グラデーションは底部で終了するはずでした。 CGRectMake(myTableView.bounds.origin.x、myTableView.bounds.origin.y、myTableView.bounds.size.width、myTableView.bounds:

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

CGRect currentBounds = self.bounds; 
CGPoint topCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMaxY(currentBounds)); 
CGPoint bottomCent = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMinY(currentBounds)); 
CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, bottomCent, 0); 

CGGradientRelease(glossGradient); 
CGColorSpaceRelease(rgbColorspace); 
1

あなたはMYVIEWにautoresizemaskを設定することがありますか?可変の高さと幅に設定してみてください。

また、myViewのフレームをmyTableView.boundsではなくself.boundsに設定しています。

+0

この 'のUIView * MYVIEW = [[GradientBackground ALLOC] initWithFrameを試してみました。 size.height)]; myView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 'しかし、私は運がなかった。 – Faser

関連する問題