objective-c - UITableView 背景只填充了一半?

标签 objective-c ios ipad uitableview background

不幸的是,我用背景 View (渐变)填充了我的 tableView,只有一半的背景被填充了。

有什么想法可以填补下半场吗?

非常感谢!

代码:

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

最佳答案

您是否在 myView 上设置了 autoresizemask?尝试将其设置为可变高度和宽度。

您还将 myView 的框架设置为 self.bounds 而不是 myTableView.bounds。

关于objective-c - UITableView 背景只填充了一半?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8657919/

相关文章:

ios - 如何确定我的静态库是否正常工作

iphone - 从 iOS 中的 iPhone 相机库将图像发布到 Facebook

ios - 使用 “IF” 语句弹出到两个可能的 View Controller

ios - 更新应用程序时如何强制删除 NSUserDefaults?

ios - Xcode 8.2 : UIPageViewControllerDatasource method broken

ios - 将 SwiftyJSON 中的元素添加到 Swift 中的 URL 数组

iphone - Xcode "AppDelegate *const __strong' 到不兼容类型的参数”错误

ios - 如果 UISupportedInterfaceOrientations 仅设置为纵向,则检测 iPhone 方向事件?

javascript - 如何从正文中反转 e.preventDefault() ?

ipad - UISplitViewController 是否必须是 iPad 应用程序的根 Controller ?